Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 418a63c

Browse files
author
Amogh Singhal
authored
Update Interview_Questions.md
1 parent 89f8aa7 commit 418a63c

File tree

1 file changed

+84
-67
lines changed

1 file changed

+84
-67
lines changed

‎Interview_Questions.md‎

Lines changed: 84 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -38,75 +38,75 @@ Solution: There are many types of sorting algorithms: quick sort, bubble sort, b
3838

3939
## Some common algorithm problems asked at online tests :
4040

41-
### 10. Save all leaf nodes of a Binary tree in a Doubly Linked List by using Right node as Next node and Left Node as Previous Node.
41+
#### 10. Save all leaf nodes of a Binary tree in a Doubly Linked List by using Right node as Next node and Left Node as Previous Node.
4242

43-
### 11. Given an array,find the maximum j – i such that arr[j] > arr[i]
43+
#### 11. Given an array,find the maximum j – i such that arr[j] > arr[i]
4444

45-
### 12. Remove Alternate Duplicate characters from a char array you have to do it in Place.Like keeping only the odd occurences of each character.
45+
#### 12. Remove Alternate Duplicate characters from a char array you have to do it in Place.Like keeping only the odd occurences of each character.
4646
`Example: Input: "you got beautiful eyes"
4747
Output: "you gtbeaiful es"`
4848
Allowed Time Complexity was O(n) and Space Complexity was O(1)
4949

50-
### 13. In a file there are 1 million words . Find 10 most frequent words in that file.
50+
#### 13. In a file there are 1 million words . Find 10 most frequent words in that file.
5151

52-
### 14. Find all nodes at k-distance from a given node in a binary tree
52+
#### 14. Find all nodes at k-distance from a given node in a binary tree
5353

54-
### 15. Clone a linked list with next and random pointer
54+
##### 15. Clone a linked list with next and random pointer
5555

56-
### 16. Serialise and Deserialise a linked list with next and random pointer.
56+
#### 16. Serialise and Deserialise a linked list with next and random pointer.
5757

58-
### 17. Construct a binary tree from given inorder and preorder traversals.
58+
#### 17. Construct a binary tree from given inorder and preorder traversals.
5959

60-
### 18. Return a tree such that each internal node stores sum of all its child nodes. Each leaf node stores zero.
60+
#### 18. Return a tree such that each internal node stores sum of all its child nodes. Each leaf node stores zero.
6161

62-
###20. How will you implement linked list with 1 million nodes? How will you access 999999 th node? Give some optimal design strategy and implementation.
62+
#### 19. How will you implement linked list with 1 million nodes? How will you access 999999 th node? Give some optimal design strategy and implementation.
6363

64-
###21. Reversal of Linked List in groups of K.
64+
#### 20. Reversal of Linked List in groups of K.
6565

66-
###22. Given a positive integer N, count all possible distinct binary strings of length N such that there are no consecutive 1’s.
66+
#### 21. Given a positive integer N, count all possible distinct binary strings of length N such that there are no consecutive 1’s.
6767

68-
###23. Check whether given binary tree is balanced or not. Definition was no two leaves should have height difference of greater than one.
68+
#### 22. Check whether given binary tree is balanced or not. Definition was no two leaves should have height difference of greater than one.
6969

70-
###24. Remove duplicates from string in place in O(n).
70+
#### 23. Remove duplicates from string in place in O(n).
7171

72-
###25. Connect nodes on same level in a binary tree.
72+
#### 24. Connect nodes on same level in a binary tree.
7373

74-
###26. Find sum of data of all leaves of a binary tree on same level and then multiply sums obtained of all levels.
74+
#### 25. Find sum of data of all leaves of a binary tree on same level and then multiply sums obtained of all levels.
7575

76-
###27. Given a matrix of characters and a word. You have to count the number of occurrences of that word in that matrix. you can move to any of the eight valid directions from current position.
76+
#### 26. Given a matrix of characters and a word. You have to count the number of occurrences of that word in that matrix. you can move to any of the eight valid directions from current position.
7777

78-
###28. You are given an string as input which represents a path. You have to normalize that path inplace(NO EXTRA SPACE).
78+
#### 27. You are given an string as input which represents a path. You have to normalize that path inplace(NO EXTRA SPACE).
7979
`e.g.input : "\a\b\c\..\..\file.txt" output: "\a\file.txt"`
8080

81-
###29. Least common ancestor of two nodes in a binary tree
81+
#### 28. Least common ancestor of two nodes in a binary tree
8282

83-
###30. Given two sorted arrays (with repetitive elements) find the kth minimum number from both arrays.
83+
#### 29. Given two sorted arrays (with repetitive elements) find the kth minimum number from both arrays.
8484

85-
###31. Given the root to a binary tree, a value n and k.Find the sum of nodes at distance k from node with value n
85+
#### 30. Given the root to a binary tree, a value n and k.Find the sum of nodes at distance k from node with value n
8686

87-
###32. Find an element in a rotated array. The cost of a stock on each day is given in an array, find the max profit that you can make by buying and selling in those days.
87+
#### 31. Find an element in a rotated array. The cost of a stock on each day is given in an array, find the max profit that you can make by buying and selling in those days.
8888
`For example, if the given array is {100, 180, 260, 310, 40, 535, 695},
8989
the maximum profit can earned by buying on day 0, selling on day 3.
9090
Again buy on day 4 and sell on day 6.
9191
If the given array of prices is sorted in decreasing order, then profit cannot be earned at all.`
9292

93-
### 32. Given two linked lists both represent a number. Create a linked list that contains its sum.
93+
#### 32. Given two linked lists both represent a number. Create a linked list that contains its sum.
9494

95-
### 33. Given a binary search tree , print the path which has the sum equal to k and has minimum hops. i.e if there are multiple paths with the sum equal to k then print the path with minimum number of nodes.
95+
#### 33. Given a binary search tree , print the path which has the sum equal to k and has minimum hops. i.e if there are multiple paths with the sum equal to k then print the path with minimum number of nodes.
9696

97-
### 34. A MxN matrix containing integers (positive, negative and zero’s). For every position containing 0, mark the corresponding row and column as 0. Rotate MxN matrix by 90 degress.
97+
#### 34. A MxN matrix containing integers (positive, negative and zero’s). For every position containing 0, mark the corresponding row and column as 0. Rotate MxN matrix by 90 degress.
9898

99-
### 35. Find the nth number that contains the digit k or is divisible by k. (2 <= k <= 9)
99+
#### 35. Find the nth number that contains the digit k or is divisible by k. (2 <= k <= 9)
100100

101-
### 36. Write a program to connect next left node in a binary tree. Also first node of each level should be pointing to last node of next level? (Without using Queue)
101+
#### 36. Write a program to connect next left node in a binary tree. Also first node of each level should be pointing to last node of next level? (Without using Queue)
102102

103-
### 37. Convert a binary tree to its sum tree(each node is the sum of its children)
103+
#### 37. Convert a binary tree to its sum tree(each node is the sum of its children)
104104

105-
### 38. Given a directed graph. Construct another graph from given graph such that if path exists from vertices A to vertices B and from B to C, then path from A to C and from C to A also should exists.
105+
#### 38. Given a directed graph. Construct another graph from given graph such that if path exists from vertices A to vertices B and from B to C, then path from A to C and from C to A also should exists.
106106

107-
### 39. Implement hashmap on your own. Write good hashing function for string.
107+
#### 39. Implement hashmap on your own. Write good hashing function for string.
108108

109-
### 40. Given an array, arrange the elements such that the number formed by concatenating the elements is highest.
109+
#### 40. Given an array, arrange the elements such that the number formed by concatenating the elements is highest.
110110
`E.g.: input = [9, 93, 24, 6],
111111
the output should be: [9,93,6,24].
112112
This is because if you concatenate all the numbers,
@@ -131,37 +131,50 @@ the output should be: [9,93,6,24].
131131
7th smallest number = 15 and so on.`
132132

133133
#### 49. Given an array which is first strictly increasing and then strictly decreasing. Find an element in this array.
134-
Given a string example : shoppingwithflipkartiseasy, Now we are given this string and a dictionary containing valid words , now we need to break the sentence into words separated by space. Output : shopping with flipkart is easy
135-
Given a series 2,3,4,5,6,8,9,10,......, here in this series all the numbers are present which have factors only and only either 2,3 or 5. Need to write a node to generate nth number for the series . With best approach and complexity
136-
Given a tree with edge weights, find any path in the tree with maximum sum of edges.
137-
Merge k sorted arrays.
138-
Given a maze, a start point and end point find the shortest path to reach the end point from the starting point.
139-
Given a sentence and a set of characters. Find the minimum window within which the set of characters can be found in the sentence in any order.
140-
You are given a string of 0’s and 1’s you have to find the number of substrings in the string which starts and end with a 1.
141-
eg : input : 0010110010 output : 6
142-
You are given a mapping like a -> 1, b-> 2... z-> 26. You have to print all possible combinations of a given number using the above information.
143-
eg : input : 121 output : aba,la,au
144-
Given a dictionary of 50,000 words. Given a phrase without spaces, add spaces to make it a proper sentence.
145-
e.g:input: thequickbrownfoxjumpoverlazydog
146-
output: the quick brown fox jump over lazy dog
147-
Given an unsorted array of n integers which can contain integers from 1 to n. Some elements can be repeated multiple times and some other elements can be absent from the array. Count frequency of all elements that are present and print the missing elements.
148-
Examples:Input: arr[] = {2, 3, 3, 2, 5}
134+
135+
#### 50. Given a string example : shoppingwithflipkartiseasy, Now we are given this string and a dictionary containing valid words , now we need to break the sentence into words separated by space. Output : shopping with flipkart is easy
136+
137+
#### 51. Given a series 2,3,4,5,6,8,9,10,......, here in this series all the numbers are present which have factors only and only either 2,3 or 5. Need to write a node to generate nth number for the series . With best approach and complexity
138+
139+
#### 52. Given a tree with edge weights, find any path in the tree with maximum sum of edges.
140+
141+
#### 53. Merge k sorted arrays.
142+
143+
#### 54. Given a maze, a start point and end point find the shortest path to reach the end point from the starting point.
144+
145+
#### 55. Given a sentence and a set of characters. Find the minimum window within which the set of characters can be found in the sentence in any order.
146+
147+
#### 56. You are given a string of 0’s and 1’s you have to find the number of substrings in the string which starts and end with a 1.
148+
`eg : input : 0010110010 output : 6`
149+
150+
#### 57. You are given a mapping like a -> 1, b-> 2... z-> 26. You have to print all possible combinations of a given number using the above information.
151+
`eg : input : 121 output : aba,la,au`
152+
153+
#### 58. Given a dictionary of 50,000 words. Given a phrase without spaces, add spaces to make it a proper sentence.
154+
`e.g:input: thequickbrownfoxjumpoverlazydog
155+
output: the quick brown fox jump over lazy dog`
156+
157+
#### 59. Given an unsorted array of n integers which can contain integers from 1 to n. Some elements can be repeated multiple times and some other elements can be absent from the array. Count frequency of all elements that are present and print the missing elements.
158+
`Examples:Input: arr[] = {2, 3, 3, 2, 5}
149159
Output: Below are frequencies of all elements
150-
1 -> 0 2 -> 2 3 -> 2 4 -> 0 5 -> 1
151-
Get the next bigger number using the same digits of a number.
152-
Eg, For 123456, next number would be 123465
153-
Given a boolean 2D matrix, find the number of islands. A group of connected 1s forms an island. For example, the below matrix contains 5 islands
154-
Input : mat[][] =
160+
1 -> 0 2 -> 2 3 -> 2 4 -> 0 5 -> 1`
161+
162+
#### 60. Get the next bigger number using the same digits of a number.
163+
`Eg, For 123456, next number would be 123465`
164+
165+
#### 61. Given a boolean 2D matrix, find the number of islands. A group of connected 1s forms an island. For example, the below matrix contains 5 islands
166+
`Input : mat[][] =
155167
{{1, 1, 0, 0, 0},
156168
{0, 1, 0, 0, 1},
157169
{1, 0, 0, 1, 1},
158170
{0, 0, 0, 0, 0},
159171
{1, 0, 1, 0, 1}}
160-
Output : 5
161-
Given two strings in lowercase, the task is to make them anagram. The only allowed operation is to remove a character from any string. Find minimum number of characters to be deleted to make both the strings anagram?
172+
Output : 5`
173+
174+
#### 62. Given two strings in lowercase, the task is to make them anagram. The only allowed operation is to remove a character from any string. Find minimum number of characters to be deleted to make both the strings anagram?
162175
If two strings contains same data set in any order then strings are called Anagrams.
163176

164-
Examples:
177+
`Examples:
165178

166179
Input : str1 = "bcadeh" str2 = "hea"
167180
Output: 3
@@ -171,11 +184,12 @@ Input : str1 = "cddgk" str2 = "gcd"
171184
Output: 2
172185

173186
Input : str1 = "bca" str2 = "acb"
174-
Output: 0
175-
Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
187+
Output: 0`
188+
189+
#### 63. Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.
176190
Examples:
177191

178-
Input: arr[] = {2, 0, 2}
192+
`Input: arr[] = {2, 0, 2}
179193
Output: 2
180194
Structure is like below
181195
| |
@@ -199,8 +213,9 @@ Output: 6
199213
| || |
200214
_|_||_||||||
201215
Trap "1 unit" between first 1 and 2, "4 units" between
202-
first 2 and 3 and "1 unit" between second last 1 and last 2
203-
Given two strings str1 and str2 and below operations that can performed on str1. Find minimum number of edits (operations) required to convert ‘str1’ into ‘str2’.
216+
first 2 and 3 and "1 unit" between second last 1 and last 2`
217+
218+
#### 64. Given two strings str1 and str2 and below operations that can performed on str1. Find minimum number of edits (operations) required to convert ‘str1’ into ‘str2’.
204219
Insert
205220

206221
Remove
@@ -209,7 +224,7 @@ Replace
209224

210225
All of the above operations are of equal cost.
211226

212-
Examples:
227+
`Examples:
213228

214229
Input: str1 = "geek", str2 = "gesek"
215230
Output: 1
@@ -224,11 +239,12 @@ Output: 3
224239
Last three and first characters are same. We basically
225240
need to convert "un" to "atur". This can be done using
226241
below three operations.
227-
Replace 'n' with 'r', insert t, insert a
228-
Given a string with repeated characters, task is rearrange characters in a string so that no two adjacent characters are same.
242+
Replace 'n' with 'r', insert t, insert a`
243+
244+
#### 65. Given a string with repeated characters, task is rearrange characters in a string so that no two adjacent characters are same.
229245
Note : It may be assumed that the string has only lowercase English alphabets.
230246

231-
Examples:
247+
`Examples:
232248

233249
Input: aaabc
234250
Output: abaca
@@ -240,8 +256,9 @@ Input: aa
240256
Output: Not Possible
241257

242258
Input: aaaabc
243-
Output: Not Possible
244-
This problem is know as Clock angle problem where we need to find angle between hands of an analog clock at a given time.
245-
Examples:Input: h = 12:00, m = 30.00
246-
Output: 165 degreeInput: h = 3.00, m = 30.00 Output: 75 degree
259+
Output: Not Possible`
260+
261+
#### 66. This problem is know as Clock angle problem where we need to find angle between hands of an analog clock at a given time.
262+
`Examples:Input: h = 12:00, m = 30.00
263+
Output: 165 degreeInput: h = 3.00, m = 30.00 Output: 75 degree`
247264
————————————————————————————————

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /