Interview 1:
Before the interview began we were asked to solve 6 questions
- Write a function to swap a number in place without temporary variables.
- Find out if number is power of 2.
- Find the least common ancestor of 2 nodes in a BST.
- Write a method to replace all spaces in a string with '%20'.
- Check if binary tree is balanced.
- Implement an algorithm to find the nth to last element of a singly linked list.
- Assume you have a method isSubstring which checks if one word is a substring of another. Given two string write code to check is s2 is a rotation of s1 using only one call to isSubstring (i.e. "waterbottle" is a rotation of "erbottlewat")
struct node{
int data;
vector < struct node* > child;
}
then we have the number of children of each node as nodeName->child.size();
we use it to compare the first child of the node with the last child, 2nd with 2nd last and so on:
Round 3
Q1) Write a C code to evaluate an expression tree.
Answer-> It has to be done in a post order traversal method, since the value of the left subtree is independent of the right subtree.
Q2) Articulation Points (or Cut Vertices) in a Graph - GeeksforGeeks -> Check for Articulation points
Q3) Given a stream of number, like 1,3,5,4,6,9 print 1,3-6,9
Answer-> create a hash map that contains the value of the ending index of the previous sequence.
For example when we get 1,3,5 the hash map is 1 0 3 1 5 2key is the number and the value is the index where it occurs. when we get 4, we have to check for the index of 3 and 5. (One above and one below) the value at 3 is 1 and 4's index is 3, so they can't be paired. We then check for 5. 5's index is 2 and 4's is 3, since they are together, they can be paired.
1 0 3 1 5 2-3 4 2-3and then we check for 3 again, 3's index is 1 and 4's index is 2-3, so they can match
1 0 3 1-3 5 1-3 4 1-3We go on. I don't think I answered the questions the way it was asked, but he seemed ok with the answer I gave. Next he modified more to include distributed systems in it. And asked me if there were several systems which received the input in round robin manner, how would I implement the above algorithms. I had no idea about this. After round 3, I was called by Amazon and told that my first two rounds were positive but round 3 wasn't. Round 3 was the hiring manager round, and he wasn't happy that I had little idea about RAID ( Standard RAID levels - Wikipedia, the free encyclopedia ) So I had another hiring manager round. Round 4 https://www.geeksforgeeks.org/dsa/find-a-pair-with-given-sum-in-bst/ Find a pair with a given sum in a bst more questions on what happened in Round 3 and why I want to leave my current firm. Round 5 (Bar Raiser) Questions like 1) tell me a time when you had a different opinion than the rest of the team. 2) tell me a time when you were thinking that the problem is something else, but it turned out to be something else 3) tell me a time when your opinion were discarded. 4) tell me a time when you had to work on a very short notice. Coding questions- 1) given that we can form packs of 6,9 and 20 pens. Given a number x, calculate if we can form combinations of packs to form those many pens. Eg 24 pens can be formed by having 2 packs of 9 pens and 1 of 6 and 23 pens can't be formed. Answer Dynamic Programming with the recursive function DP[i]=DP[i-6]||DP[i-9]||DP[i-20]; 2) Design an escalator system. Which classes would you make, etc. After Round 5, they didn't find me a cultural fit so they conducted a Round 6. Round 6 Questions like- tell me something about yourself, a time when you helped someone A time when you shared a different opinion from your manager.