Eligibility Criteria: CGPA >= 5.0
Round 1: Technical Test
An online test held on HackerRank which consists of 20 MCQ’s and 2 coding questions.
- Coding Question 1: Find a tour that visits all the stations
- Coding Question 2: 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).
They were pretty simple you just need to have basic knowledge about Scheduling Algorithms, Threads and Time Complexity. In this section major portion was from the Operating Systems.
I would suggest you go through last minute notes on OS, they were life savior for me in Online round as well as in further round.
We were told that there will be only 2 Technical Rounds and No HR round.
Face to Face Round 1: (~1 hour)
- Questions 1: Fold a LinkedList :1 ->2->3->4->5->6 is converted to 1->6->2->5->3->4
My approach :
- Step 1: Find the middle of the link list.
- Step 2: Reverse the second half of the link list and keep the head as head2 for the second half of the linklist.
Second Half after reversal
Now traverse both the halves simultaneously and then take a node from first list and then from second list, do this until you reach the end of first and second list and make new links and maintaining the links to the next Node. Asked me to cover all corner cases.
Finally asked me to give a proper working code on paper.
- Question 2:
If one of the nodes in BST in not is correct position place that in correct position in the bst. First by some observation I figured out that the there will 2 nodes which will be in wrong order.
So this question became similar to Two nodes of a bst are swapped ,correct the bst. I gave an in order traversal approach but missed some corner cases, after giving a few he told me I am missing some more test cases, then he moved to next question.
- Question 3:
A music player has N songs , you have a random number generator rand(n) which generates a number from [0,n-1] .Your task is to play a random song from given N songs such that each song is played once and your program should terminate once you have played all the songs.
- Approach 1:
We will use a HashMap to store the index of the song played and then whenever a random song is played check its occurrence in the HashMap if it is already there generate a random number again and do this till the size of the HashMap is N.
He told me that is a buggy code, and asked me to find out the bug.
The problem with the code is that it might end in an infinite loop in the worst case, assume that the first time rand(n) generates a number k (k<n) and we put that in the hashmap , now assume every time the rand(n) generates k so we will end into an infinite loop and our program might never terminate.After a lot of thinking, I couldn’t come up with a good approach.
Hint given by interviewer: What if you can swap some of the songs?
- Approach 2:
Step 1: Take a variable last initialize it to N.
Step 2: Generate a random number using rand(last),let it be k.
Step 3: Swap(a[last-1],a[k])
Step 4: last–;
Step 5: Goto Step 2 till all the songs are played(last!=0)By the last variable I simply keep track of all the songs that are played(after last).
He was satisfied with the approach.
- Approach 1:
Round 1 was over.
Face to Face Round 2 (~1.5 hour)
- Question 1:
He started with graphs asked to find the followers of a person told him to do a bfs and some basic questions related to bfs.
- Question 2: Clone a LinkList with random pointers.
Gave him a solution using Hash Map, he was not satisfied asked me to do in O(1) extra space.
I thought for 20 minutes but couldn’t come with the O(1) approach.
Hint given by interviewer: What if you change some links in the original list?
Again thought for about 10 minutes still couldn’t come with an O(1) approach.
Then he asked me to code the HashMap approach, while coding I figured out the approach with O(1) extra space. Once I was done with the code I told him the other approach, he was satisfied, code wasn’t required for the second approach.
- Question 3: If you have 2 very big numbers how will you add them? Told him BigInteger is there in Java use that.
I : No without using that.
Take two strings and simply convert every character to digit and then add them up.
I: No you don’t have to convert a character to a digit.
Take 2 arrays.
I: Tell the constraints with the array.
Then I finally told him to use a LinkList.
And then finally told me the approach to add them without reversing the list.(Did by recursion)
- Then there were many small questions related to quick sort, heaps, hashing, time complexity for various algorithms.
What are different phases in Compiler?
I never expected that!
I thought for about 2 minutes and tried to collect as much as possible whatever I have read in Compiler design. Then I gave him 4 phases of Compiler: Lexical Analyzer, Syntax Analyzer, Semantic Analyzer, Intermediate Code generation and then told him that I don’t remember anything more that this since I haven’t prepared CD and studied a long time ago.
- Then he asked me questions from OS.
What is Threading?
Why thread better then process?
What is thrashing?
What is LRU?
And some more basic questions on OS.
That was all for the interview.
Result: Selected 😀
Best of Luck to all of geeks for their placement season!!
If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above