Sunteți pe pagina 1din 14

ROUND 1: Written

1. Given a list of n strings group all anagrams together


2. Given a binary square matrix of size n, find the size of largest region i.e. find a region
of connected ones (horizontally, diagonally, vertically).
3. Find the next greatest number using digits for a given number. STL usage is
allowed!
4. In a given array A find the maximum value of |Ai – i| – |Aj – j| where i not equal to j.
5. Given an expression string exp, write a program to examine whether the pairs and
the orders of “(” and “)” are correct in syntax.
6. Given preorder and inorder traversal of a binary tree, print preorder and inorder of
the tree after modifying it such that each node stores the sum of its left and right
subtree.
7. Given a string print the lexicographically smallest possible rotation of the string.
8. Balanced parenthesis.
9. Given a string, check whether string is Good or Bad(Condition – String is composed
of ‘a’ and ‘b’ characters only and you can add only “ab” anywhere in the string to form
a Good string).
10. Find next greater element with same set of digits.
11. Find max(|Ai – i| – |Aj – j|) from an array with i!=j.
12. Sort a linked list which consists of only 0s,1s and 2s.
13. Find the maximum product of three elements in an array which consists of both +ve
and -ve numbers.
14. Given a number find the next greatest number formed with same digits
15. Find the largest increasing sequence in an array.
16. Given a set of words find the number of anagram for each word in given set of
words.
17. Find diameter of binary search tree in O(n) complexity.
18. Given a linked list retain the first i elements and delete the next j elements.
19. Given an array of number give a permutation of array which when converted to a
number is the greatest.
20. Given a binary tree , connect all the nodes at the same level with a next pointer.
21. Given a sorted,pivoted array search for an element.
22. Write a program to separate even nodes from odd nodes and odd nodes must come
after even nodes(in place).
23. Find if the Robot moves in Circular fashion.
24. Given a linked list, check whether it is palindrome or not.
25. Given a matrix of NxM, consisting of alphanumeric characters, print the matrix
spirally.
26. Given a set of time intervals in any order, merge all overlapping intervals into one
and output the result which should have only mutually exclusive intervals.
27. Josephus problem with k = 2.
28. Find the first non-repeating character in a string.
29. Zig Zag traveral in a binary tree.
30. Finding the next higher palindromic number using the same set of digits.
31. Difference between map and unordered_map
32. .Given a string. Find all the palindromic partitions of the string. (Number of way the string
can be partitioned so that all the partitions are palindrome) ( Case–Insensitive )
Examples:
Input : NITIN
Output : 3

Input : AAa
Output : 4
33. Given a n-ary tree print all the possible paths of the tree.
34. Given the no. of stairs as the input and a person can step forward either 1 or 2 or 3 steps
at a time. Find the total no of possible ways person can climb the stairs.
Input : 3
Output: 4
35. Given a 1-D array having equal no even and odd numbers. Arrange the numbers in such
a way that all the even no get the even index and odd no get the odd index. Required
space complexity and time complexity was O(1).
36. given a point (x,y) which is position of a friends house on a coordinate plane. and a
person starts from(0,0),and can move only on x-axis. each time he moves double the
steps from previous step and in opposite direction.he starts by taking 1 step in positive x
axis. each step he takes 1 second. given a time n. we have to find the distance between
his friends house and his position after n seconds.
37. given a string and an integer m that denotes number of changes that can be made on
the given string.we have to find maximum length of a sub string that can be formed by
doing m number of changes such that all alphabets in the substring are same.
38. Rearrange nodes in the given linked list as follows
input : a -> b -> c -> d -> e
output: a -> e -> b -> d -> c
39. Given an array of integers, print pairs(positive value and negative value of the number)
that exists in the array
input : [1, -3, 2, 3, 6, -1]
output : [-1,1]
[-3,3]

40. given row wise and column wise 2d matrix, find k minimum elements
41. given an array and a window size and window moves from left to right till the rightmost
side of window hits the other side of array, print max element in the window for
each step in the process
42. 1.Given a string. Find all the palindromic partitions of the string. (Number of way the
string can be partitioned so that all the partitions are palindrome)( Case – Insensitive )
Examples:
Input : NITIN
Output : 3

Input : AAa
Output : 4

43. Given a range [L,R] find the count of numbers having prime number of set bits in their
binary representation. [This hint was included in O/P section. Only even numbers should
be checked within the L,R range]
Examples:
Input : 6 10
Output :2
6 -> 110 (2 set bits, 2 is prime)
10->1010 (2 set bits , 2 is prime)
so 6,10 are even numbers having prime number of set bits
(Use the optimized way to check prime by creating a array
of prime numbers and trying to divide the setbit count
to check if it is prime or not).

44. Given n lines a land can be split into many areas of different measure(say b). You are
provided with a constant K . You have to find whether it is possible to use K areas from
the B areas
Input : 2 4
Output : True
Think of a circle whenever a circle is split by
a n line the total number of areas is given by n*2
so the answer will be if(n*2>=k||n+1==k) return True.

45. Given an array find all the triplets having their sum of elements less than a given number
k.
46. Given a string you have to partition it in such a way that each part of the partitioned
string is a palindrome in itself and you have to count the number of such partitions.
Input: NITIN
Output: 3
Explaination: The 3 possible partitions are N | ITI | N, N | I | T | I | N, NITIN
47. Given a binary tree, if parent is 0, then left child is 0 and right child is 1. if parent is 1,
then left child is 1 and right child is 0. Root of the tree is 0.
48. Find the maximum length of the subarray with sum zero in an array of integers.
Subarray with sum zero : is formed when elements repeat in cumulative sum array and
maximum length
subarray can be obtained by maintaining first occurence of the element.
49. Find LCA (lowest common ancestor) of two nodes in a binary tree.
50. Given an array find all sets of size 3 having sum of elements less than a given number k.
51. Find n-th magic number.
52. Given a set of 2 alphabets (A, B), find the number of strings of given length that can be
formed such that the string contains at least one set of three consecutive B’s.Examples:
Input: 3 Output: 1 Input: 4 Output: 2
53. There are ‘n’ friends who bring gifts to a Halloween party and they exchange their gifts
and the array of the number of gifts each person receives is given to you. Check if such
an arrangement (array) is possible and if it’s possible then, given an arrangement of the
same.
Examples:
Input:
3
111
Output: 2 3 1
54. Find the maximum sum of lengths of non-overlapping contiguous subarrays with k as the
maximum element.
Ex: Array: {2,1,4,9,2,3,8,3,4} and k = 4
Ans: 5
{2,1,4} => Length = 3
{3,4} => Length = 2
55. So, 3 + 2 = 5 is the answer
56. Magic numbers are defined as either powers of 5, or sum of unique powers of 5. Find
nth magic number. Eg: 5,25,30,125,130 etc.
57. Print matrix in diagonal form
58. Given an array consisted of both positive and negative integers. The task was to put
positive and negative elements alternatively and efficiently.
59. Given arrival and departure times of Train. The task was to find out minimum number of
platform needed.
60. In coding section there was an easy question which was based on strings and brute
force based. The question was to ch-eck if the substring of one given string is an
anagram of the other.
61. Input: zamo amazon
Output: Yes
62. Second question was of moderate level in which input is an expression string and you
have to evaluate that given string is valid. If yes return the value of the expression, else
return -1.
63. Input : 5+7*2
Output : 19
Input : 5++4
Output : -1
64. Given an expression containing alphanumeric characters and parenthesis, check if “(”
and “)” are balanced
65. Given a rectangular matrix and n moves. If you are at a position (x,y) , you can move to
(x+1,y) , (x-1,y), (x,y+1), (x,y-1). What is the probability that after n moves ,you will
remain inside the rectangle?
66. A program to check if a binary tree is BST or not
67. Given a binary tree, we need to check if it’s a binary search tree. He wrote the following
function
bool is BST(Node *root)
68. Maximum sum such that no two elements are adjacent Given an array of positive and
negative numbers find the maximum sum in the array such that no two elements are
adjacent.
69. An array consists of 0’s and 1’s. A flip operation is one in which you turn 1 ? 0 and a 0 ?
1.You have to do a “Flip” operation at most once on a sub array. Then finally display the
maximum number of 1 you can have in the array after one flip operation.
In both the questions brute force solutions were accepted, i.e O(n^2).
70.

ROUND 2: Technical
1. Reverse a linked list.
2. Print top view of a binary tree.
3. Check if a given binary tree is a Binary Search Tree.
4. Implement Stack using Arrays Linked Lists and Queues. And comment on their
advantages and disadvantages.
5. Implement Queues using Stacks and comment on the complexity.
6. Given a string of characters find the first non repeating character.
7. Given a list of vehicles group vehicles by their property.
8. suppose there is a matrix filled with zeros and ones then find if there is a path
between (0,0) to (n-1,m-1 ).
9. Game of nim
10. Number of all possible bst for keys 1 to n
11. number of all possible labeled binary trees for given n nodes
12. From an Unthreaded B.S.T delete all the nodes with a single child and explain its
complexity.
13. A sorted array is rotated K times, find the index of the largest number.
14. Largest Palindromic Substring from a string.
15. Finding nth node from end of linked list
16. Deleting nth node from end of linked list.
17. print a binary tree diagonally.
18. how to insert node in binary search tree using recursion and without recursion.
19. Given a binary tree how to find the least common ancestor of two nodes in the tree.
20. Given a binary search tree find the least common ancestor of the two nodes in tree.
21. Print a matrix spirally.
22. How to deserialize and serialize a binary tree.
23. Given a binary tree, find the longest path in the tree. If there are two longest paths
print the lexicographically first path.
EXAMPLE:

24.
25. Find the largest rectangular area possible in a given histogram where the largest
rectangle can be made of a number of contiguous bars. For simplicity, assume that
all bars have same width and the width is 1 unit.
26. Border traversal of a complete binary tree.
27. Given a linked list, write a function to reverse every k nodes.
28. Given an array arr[] of integers, find out the maximum difference between any two
elements such that larger element appears after the smaller number in arr[]. Print the
indices of the two elements also.
29. Finding compliment and 2s compliment of a binary number (Didnt have to code it just
find it for say 100011)
30. A variant of Binary tree traversal. I was given a tree and the output was given had to
identify the type of traversal and then code it out.
31. It was right_subtree->left_subtree->root
32. Stock buy sell to maximize profit problem
33. given an array we have to find the median of the array when it is sorted but we
should not sort it.
34. Given a positive number and you have to find all the no. that holds the property of all
the digits with absolute difference equal to 1 to its adjacent digit below that given
number.
Input : 40
Output : 10 12 21 23 32 34

35. Given a tree and a element K . Find the root-leaf path with a sum equalling K and
delete the path.
36. given a BST with additional information at each node howmany nodes in its left
subtree and right subtree. find the kth largest element in that tree.
37. merge two sorted linked list.
38. Find the vertical sum of all nodes in a given binary tree.
39. Find the maximum area under a given histogram.
40. Find the zig-zag traversal of a given binary tree.
41. Find ‘k’th node’s value from the end in a given binary tree.
42. Add ‘1’ to a given number (in the form of a singly linked list) without reversing the
linked list.
43. Find a triplet among the given numbers that satisfies a + b = c.
44. Find the largest repeated sub-sequence in a given string.
45. Given an infinitely large array, find the given element.
46. Maximum rain water that can be trapped in the given set of buildings.
47. Given an infinitely large array and every element has tags associated with them,
and there are about 10,000 tags (say) then sort the given array to get all tag-0’s first,
tag-1’s next and so on in O(n).
48. Search for an element in a row-wise and column-wise sorted 2D Matrix
49. Given an array of n elements and a number, find a pair in the array with sum equal
to that number.
50. Given a binary tree and a node of that tree, find all nodes at a distance d from the
given node. Pointer to root node is given.
51. Given an array of integers, find the first non-repeating number in the array.
52. Find the longest palindromic subsequence in a given string.
53. Given a complex weighted directed graph. Each weight represents the cost of
transaction and each edge represents the transaction. The task was to minimize the
graph and find out the minimum cash flow.
54. Given an integer and decoding mechanism (like 1- A, 2-B……26-Z). The task was to
find out all the possible decoding of integer.
55. Given an Amazon Store House where every products were stored like pens, balls
etc. Also the condition was that items can be sold in bundles like 2, 3, 5, 7 etc. The
task was that how I can sell those products if some order like 10 pens has come. It
was asked to solve it in an efficient manner.
56. A matrix is given containing only 1 and 0. So whenever you access a 0 make the
entire row and column as 0.
57. Quick sort
58. 2-Questions about DBMS and DS to make it more efficient
59. 3-Find minimum and maximum number in an array with minimum number of if
statements
60. 4-Discussion about c++
61. Fold a LinkedList :
1 ->2->3->4->5->6 is converted to 1->6->2->5->3->4
ROUND 3: Technical
1. Find Kth Max occurring element in the Array.
2. Maintain the First Non-Repeating character in a stream of incoming and out going
characters or digits simply in O(1).
3. Cloning of a Binary tree with random pointer:
4. Given two numbers return the sum of the two numbers considering all the cases(like
integer overflow, underflow etc).
5. Given array of elements denoting price of some objects, print the maximum sum that
can be obtained following some constraints-
i)only one of the two ends from the array can be selected at a time
ii)the seller can sell only one item per day
iii)the value of each of the elements gets multiplies by the number of days passed.
6. Print next greater palindrome of a given array with each element denoting a single
digit of an integer.
7. Connect nodes at same level with O(1) extra space.
8. Design a data structure for a server which can store at most 100 records.
9. What is a page fault?
10. How does it affect the CPU performance?
11. How to minimize it?
12. Find median of infinite stream of integers.
13. Find all subsequences of a string.
14. Divide an integer array in 2 parts such that their sum is equal.
15. Find the last non-repeating integer in a stream of integers in O(1) time complexity.
16. What is a binary tree?
17. What are different types of traversals in a BT?
18. What is the difference between these traversals?
19. Which of the traversal is based on BFS and which is based on DFS?
20. What is a max heap?
21. What is a min heap?
22. What are some real life applications of heaps?
23. How to insert in a heap?
24. What is the time complexity?
25. How to delete a min element from a min heap?
26. What is the time complexity?
27. Given an array of n numbers, how can i build a min heap from the array. What is the
time complexity?
28. Given a stream of number how you will maintain top 10 element.
29. Write a code for Lowest common ancestor of binary tree.
30. Given an array with -ve as well as +ve elements find max continues sum.
31. Given a singly circular link list containing both +ve as well as -ve numbers find max
continues sum.
32. Given prices of stocks per day find maximum profit you can earn by buying and selling
shares.
33. Given a sorted stream of 0’s and 1’s, find the first occurrence of 1.Write a full working
code.
34. What happens when you click a web address and how are web pages retrieved.
35. write a code to make following queries within two given time stamps t1 &t2:
query 1: Return number of all the functions called between t1 & t2.

query 2: Return number of times a particular function is called between t1&t2.

36. Given an array of integers,find a subarray having least average.


37. Suggest some data structures to maintain relationship between various hierarchies in
an organization.
38. Given a BST and 2 nodes in the BST, find the length of the path between the two
given nodes
39. Given an array where the elements are in absolute difference 1, write an algorithm to
search for an element in the array and return the position of the element.
40. Given a linked list, check if it is a palindrome or not.
41. Given a tree, print the tree in Zig-Zag manner.
42. Given a sorted array find that element whose value is equal to that of its index
value.
43. Given a 2D array, find the maximum sum sub-matrix in it, also display it.
44. Given three strings A, B and C. Write a function that checks whether C is an
interleaving of A and B. C is said to be interleaving A and B, if it contains all
characters of A and B and order of all characters in individual strings is preserved.
45. Given a string, find the longest substring without repeating characters.
46. Given a log file of page visits of a website by different users for a day.
Entry in the log file is like this:

User 1 visited Page 4

User 3 visited Page 2

User 7 visited Page 9

47. Design an efficient data structure which supports queries like the following:

Which page was visited by exactly 2 users in day?

Which page was visited by only one user exactly 2 times in a day?

Which page was visited by ‘User 3? more than 5 times in a day?

48. Print all the contiguous sub-arrays where the sum of the sub-array becomes zero.
Required space complexity was O(n).
49. Given a string containing parenthesis. Find the total no of reversal of parenthesis to make
the given output as balanced one.
50. deadlocks
51. mutex vs semaphores
52. ultithreading vs multiprocessing
53. TCP protocol
54. DNS
55. 3-way handshake in TCP
56. discussion on OSI layer
57. ACID properties
58. models in DBMS(ER, network….)
59. discussion on ER model
60. What is deadlock? and situation where you have faced deadlock.
61. . Scheduling Algorithms.
62. . Code LRU Cache
63. Banker’s Algorithm.
64. . Paging , Segmentation etc.
65. How compiler compiles the interlinked libraries.
66. Find the intersection elements in 2 unsorted arrays.
67. Input: 5 4 1 3 2
12 3 15 1 7
Output: 3 1
68. Given Air tickets to different cities in the form of a pair of cities where one denotes the
source and another tells the destination.Our job is to return a linkedlist indicating the way
the travelling should travel in order to cover all the cities.(Linkedlist wasnt mentioned by
the interviewer).
69. The middle element in a linked list.
70. Merge Sort in a Double Linked List.
71. Merge Two Sorted Arrays.
72. Given A Binary Tree, For every Leaf Node print sum of the values from the root node to
the leaf node.
73. Quick Sort
74. LCA in Binary Tree and Binary Search Tree.
75. ) Print the Binary Tree in A Spiral Order.
76. 2) lli stands for long long int in this question.
77. Given two rectangles diagonally opposite coordinates. find whether a rectangle is
completely overlapping the other or not.
78. Given a binary tree create a new tree which is mirror image of that tree.
79. Given three consecutive even numbers. prove mathematically that atleast one of them is
divisible by 6.
80. Given a binary search tree, find and print all leaf nodes.
81. Convert a given binary search tree into a doubly linked list without using any additional
space.
82. Given a BST and number K (which is one of those BST). The task was to find out the
closest value to K.
83. Delete a node from doubly circular linked list.

ROUND 4: Technical

1. Given a string find a repeating substring of maximum length.


2. What is copy constructor in OOPS?
3. Explain the LRU cache technique and how to implement it.
4. Given a binary tree, a node in the tree and a distance k. Print all the nodes at a
distance k from the given node in the tree.
5. Given a huge array which is stored across 100 computers, with no way to bring them
all together, find the median of the above array.
6. Given a chess board, and a starting position, and a set number of moves, find the
probability that the knight will remain on the board after the moves are done.
7. Given a room, where N number of person are present and some comparison among
them (like A>B, B>C, B<D etch). The task was to find out the greatest among them.
8. Applications of heap. Insertion in a heap
9.
ROUND 5: Technical
1. Given an infinite integer number line, find minimum steps required to reach a
particular point. 0 is the starting point and at ith step we can move +i or -i steps from
current position.
2. Given n Runways and m Planes. How you will efficiently design this scheduling
problem so that there should not be collision.
3. Given matrix which is sorted, row wise as well as column wise like below:
01 04 07 09
11 23 45 46
51 56 59 63
70 73 75 79

find the position of key in given matrix efficiently.

S-ar putea să vă placă și