Round 1 : Online Assessment Test
Description:
I performed well in both the multiple choice sections, but was only able to solve one question in the coding section. The subjective section had 2 questions, one asking what inspires you to complete a project and one regarding a situation where one of my teammates is having problems while we are working on a project together.
I am pretty sure that I cleared the cutoff in both the multiple choice sections but still not clear as to what was the 3rd section ( most likely the subjective section, definitely not CGPA).
Round 2 : Technical Interview 1
After a brief introduction, the interviewer asked me to describe one of my projects. The discussion was more around what inspired me to do that project and the end result and practical application rather than its technical aspects. The dicussion lasted around 10-15 minutes and he was 'really impressed' (his words, not mine).
Next he asked me to speak a little on data strcutures and algorithms, the ones i like, the ones i feel were most useful etc. Somewhere in the discussion i mentioned segment trees are really elegant and useful because many problems can be reduced to some form of range query and solved using a segment tree in O(log(n)) time. I gave the example of finding the lowest common ancestor of any two nodes in a binary tree. To which he replied with the following question:
void dfs(int k,int d)
{
first_time[k]=timer;
euler[timer++]=k;
depth[k]=d;
vis[k]=1;
for(int i=0;i<adj[k].size();i++)
{
if(!vis[adj[k][i]])
{
dfs(adj[k][i],d+1);
euler[timer++]=k;
}
}
}As soon as I wrote this code for euler traversal, he gave me an example of a binary tree and asked me explain the process by dry running this code, so I filled the euler, depth and first_time arrays and he was very satisfied with my explanation.
Next I explained how I would fill the segment tree so that each node (of segment tree) tells me the node (of given binary tree) with the minimum depth in the represented segment.
After filling the segment tree, each query of lca (of a and b) would require me to just return the node with the minimum depth in the segment {first_time[a], first_time[b]}.
Time complexity: O(n) preprocessing, O(log(n)) query.
The interviewer was really impressed by this approach. But to my surprise, he asked me to optimize this solution a little more (I wasn't expecting he would ask me to optimize a solution which was alreading making use of segment tree). So I said if we store the segments in a sparse table instead of a segment tree, it would be a trade off between preprocessing time and query time reulting in:
Time Complexity: O(nlog(n)) preprocessing, O(1) query.
You would think this would be the end of discussion on this problem but no, he asked me to optimize the solution a little more. I don't know how to optimize a O(1) query so I presented him with the following solution.
Join your hands and say the following prayer: "Oh lord, here are k nodes of a binary tree, return their lca ASAP!"
Round 3 : Technical Interview 2
This round also started with 10-15 minutes of discussion on the same project, few minutes covering how it was working and rest of the discussion was same as last time.
Next he asked me the following questions
Given a number, find out the next smallest number formed by the same digits, greater than the original number (next permutation).
I proposed a solution using a queue, pushing digits starting from the unit position and going backwards until the next digit is smaller than previously pushed element at which point concatenate the last digit in queue, insert the currrent digit in the queue and concatenate the digits starting from
front of queue.
Given the schedule of a train station (the arrival and departure time of several trains), find the minimum number of platforms required at the station.
I propsed a O(nlog(n)) solution using 2 pointers after sorting the trains according to their arrival times. He asked me to make use of some data structure, so I proposed a very similar solution using a double queue.
Finally, received the offer !