I am a fourth year undergraduate CSE. I had my amazon interview in my campus.
First round was a simple round. It had 20 MCQ questions on C/C++ and 2 coding questions. The coding questions were:
1.) You are given a string that represent an expression of digits and operands. Eg. 1+2*3 , 1-2+4. You need to evaluate the string or the expression. NO BODMAS is followed. If the expression is of incorrect syntax return -1.
Test cases :
a) 1+2*3 will be evaluated to 9.
b) 4-2+6*3 will be evaluated to 24.
c) 1++2 will be evaluated to -1(INVALID).
Also, in the string spaces can occur. For that case we need to ignore the spaces. Like :- 1*2 -1 is equals to 1.
2.) You are given an array of both negative and positive integers. You need to rearrange the array such that positive and negative numbers alternate. Also, the order should be same as previous array and only O(1) auxiliary space can be used and time complexity boundation O(n).
eg. -2 3 4 5 -1 -6 7 9 1
result – 3 -2 4 -1 5 -6 7 9 1.
In this round, we were divided in groups of 5. And two problems were given and we need to write the code on paper for that problem.
My code were :
1.) You need to determine whether the linked list is palindrome or not.
2.) Print the level order traversal of the binary tree in the spiral form.[They also asked us the solution without any extra space and O(n)
Interview asked me to write the code for the two problems which are :
1.) Reverse the alternate K Nodes of the Linked List.
Result – 3->2->1->6->5->4->8->7->NULL.
2.) You are given the binary Tree and the two nodes say k1 and k2 . You need to determine whether the two nodes are cousins of eachother or not.
/ \ / \
7 8 1 3
and say two node be 7 & 1. result will be TRUE.
say two nodes are 3 & 5. result will be FALSE.
say two nodes are 7 & 5. result will be FALSE.
3.) Give the algorithm, data structures, time complexity and space complexity for the following problem :
In our mobile phones when we enter say four initials of the number say 9 4 5 6, then our phone shows the whole lists of number that starts with these entered number.
Now the problem is : how it is implemented and what is the best way of doing this keeping the balance between space and time complexity. Also, user can enter any number of initials and your program should print all the numbers with those initials that are present in your phonebook.
Interviewer asked some questions on C++ . They were :
1. What are virtual functions?
2. What is the use of virtual functions?
3. What are pure Virtual functions?
4. Syntaxes of Virtual functions and pure virtual functions?
5. What are abstract classes in C++?
6. How we can implement pure virtual functions in JAVA ?
Design question :
How we can restrict our class so that only single instance of it can be created?
What is Singleton Design Pattern?
Operating system Question :
1. What are semaphores?
2. What is producer consumer problem and give different solution for it?
Two questions he asked me to code :
1.Convert one string to another string.For that purpose you can use three operations – SUBSTITUTE,DELETE,INSERT.Each having cost as one except
substitute having cost 2.You have to determine the minimum cost required.
First String : INCLINE
Second String :DECLINE
Minimum cost required are : 4 [change I to D and N to E].
He also asked question about my projects and why I choose them. He asked to just explain the whole set of thing that I have performed in it.
(About 10 minutes discussion)
This round started with the deep discussion about my projects. Interviewer tried to get each and every aspect of my project with lot many why
and how questions.She asked me the future scope of my project and what are learnings I got from it.(About 30 minutes discussion).
Then she asked me implementation, algorithm, data structures, time complexity and space complexity for the following problem:
Say we have website having several web-pages. And also there are lot many user who are accessing the web-site.
say user 1 has access pattern : x->y->z->a->b->c->d->e->f
user 2 has access pattern : z->a->b->c->d
user 3 has access pattern : y->z->a->b->c->d
user 4 has access pattern : a->b->c->d
and list goes on for lot many users which are finite and numbered.
Now the question is we have to determine the top 3 most occurring k-Page-sequence.
for the above example result will be : (k=3) a->b->c , b->c->d , z->a->b.
[Question took the long discussion and she kept adding constraints, cases and more problems to the above problem.]
One question she asked me to code which is:
You are given a sting. Find the character in that string which is not repeated and which occur last in the sequence.
Result – x
I would like to thanks GeeksForGeeks which helped me to improve my knowledge and understanding of Data structures and Algorithms 🙂
If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.