Interview Questions for freshies
Interview Questions for freshies
Interview Questions for freshies
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:
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
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
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]
Input: s = "()[]{})"
Output: false
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/