Interview Questions for freshies

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

1) Write a function, which is given a singly linked list.

Return the result if the list is a palindrome


or not

Example:
linked list: 1 -> 2 -> 3 -> 4 -> 2 -> 1 not a palindrome linked list
linked list: 1 -> 2 -> 3 -> 1 -> 3 -> 2 -> 1 is a palindrome linked list

2) Write a function, given an array and a number. return the first and last index of the number
present in the array. If the number is not present it should return -1 on both indexes.

Example:

array: [1,2,3,4,5,3,2,1], number: 5 -> returns first index: 4, last index: 4


array: [1,2,3,4,5,3,2,1], number: 9 -> returns first index: -1, last index: -1

3) Write a function, given a singly linked list and return the reverse of the list.

Example:
linked list: 1 -> 2 -> 3 -> 4 -> 2 -> 1, returns 1 -> 2 -> 4 -> 3 -> 2 -> 1
linked list: 1 -> 3 -> 4 -> 5 -> 9 -> 0, returns 0 -> 9 -> 5 -> 4 -> 3 -> 1

4) Write a function, given an array and returns the reverse.

Example:
array: [1, 2, 3, 4, 2, 1] returns [1, 2, 4, 3, 2, 1]
array: [1, 3, 4, 5, 9, 0] returns [0, 9, 5, 4, 3, 1]

5) Write a function, given an array and a number, returns the number of occurrences in the
array.

Example:
array: [1, 2, 3, 4, 2, 1], number: 2 returns 2
array: [1, 3, 4, 5, 9, 0], number: 11 returns 0
6) Write a function, given an array, returns the second highest number from the array. Given
array would not be sorted.

Example:
array: [1, 2, 3, 4, 2, 1], returns 3
array: [1, 3, 4, 5, 9, 0], returns 5

7) Write a function, given a 2D array(matrix), returns or prints the transpose. (note the number
of rows and columns would be same)

Example:
array: [1, 2, 3]
[4, 5, 6]
[7, 8, 9]

returns: [1, 4, 7]
[2, 5, 8]
[3, 6, 9]

8) Write a function, given a 2D array(matrix), returns or prints the transpose. (note the number
of rows and columns would be different)

Example:
array: [1, 2, 3, 4]
[5, 6, 7, 8]

returns: [1, 5]
[2, 6]
[3, 7]
[4, 8]

9) Write a function, given a number: n and print the Fibonacci series till nth term.

Example:
number: 5
prints: 1, 1, 2, 3, 5

number: 7
prints: 1, 1, 2, 3, 5, 8, 13
10) Write a function, given a number: n and print the sum till the nth term.

number: 5
sum: 1 + 2 + 3 + 4 + 5 = 15

number: 10
sum: 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55

11) Write a function, given a number:n and a linked list. Print the nth term of linked list

Example:
linked list: 1 -> 2 -> 3 -> 4 -> 2 -> 1, number: 4
prints: 4

linked list: 1 -> 2 -> 3 -> 1 -> 3 -> 2 -> 1, number: 4


prints: 1

12) Write a function, given a number:n and returns whether it is a prime number or not.

13) Given an array of integers nums and an integer target, return indices of the two numbers
such that they add up to target.
You may assume that each input would have exactly one solution, and you may not use the
same element twice.
You can return the answer in any order.
Example:
Input: nums = [3,2,4], target = 6
Output: [1,2]

14) Reverse an Integer


Example :
Input: x = 123
Output: 321

15) Valid Parentheses


Example:
Input: s = "()[]{}"
Output: true

Input: s = "()[]{})"
Output: false

16) Count occurrences of every array element [Moderate]


https://www.geeksforgeeks.org/counting-frequencies-of-array-elements/

17) Remove duplicates from array


https://leetcode.com/problems/remove-duplicates-from-sorted-array/description/

18) Find the largest and second largest value in a linked list [Moderate]
https://www.geeksforgeeks.org/find-the-largest-and-second-largest-value-in-a-linked-list/

19) Swap nodes in pairs linked list [Moderate]


https://leetcode.com/problems/swap-nodes-in-pairs/description/

20) Delete node in a linked list [Basic]


https://leetcode.com/problems/delete-node-in-a-linked-list/

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy