Round 1: In the first round I was asked 2 coding questions
I was able to solve both problems. The interviewer was a very chill kind of person, first, we discussed brute force approaches, and then he asked me to optimize the solution further, and finally, I was able to give him an efficient approach. He was satisfied and then asked me to implement the code in whichever language I want. So I implemented both solutions in C++.
Round 2: Again they asked me 2 coding questions
- Given an infinite stream of integers and K, find the sum of K largest elements from stream at any point of time. This problem is similar to this one: https://www.geeksforgeeks.org/kth-largest-element-in-a-stream/
I first gave him an approach that was of O(n*k) time complexity, the idea was to keep an array of k elements in sorted order, and whenever a new integer greater than min element came drop min element and place new element in the array. But the interviewer asked me can I optimise it further, after thinking for few minutes I gave him another approach of time complexity O(n*log(k)). The idea is to maintain a min-heap of size k and if new integer is greater than min integer then simply replace the min with new integer and update the sum. The interviewer was satisfied and asked me to implement the code for the min-heap and the actual problem statement.
- Given n machines and their start time and end time to finish their work and K production line, find the minimum number of extra production lines needed to maximize the production.
Constraints: only one machine can work at a production line at a time. It is similar to this problem: https://www.geeksforgeeks.org/maximum-number-of-overlapping-intervals/.
Solution: let m be a maximum number of overlapping intervals then if m<= k ans will be 0. Otherwise, ans will be m-k. The interviewer also gave me hints if I was stuck anywhere.
Then at the end, they ask me behavioral/situational questions based on their Leadership Principles.
- Tell about any project you did in which you have used new technology that was not known to you. So, this question basically talks about Amazon’s Leadership Principles: Dive Deep, Learn and be Curious
At Amazon they mainly aiming to know your thought process, the way you approach a problem, and how quickly you came to an optimized solution. So, always discuss or tell them your approach first, then try to optimise it and also do not forget about edge cases they are very important, do ask clarification questions if needed and tell them your assumption if any and then discuss your final approach, it’s time complexity and space complexity and do compare with other algorithms and then if interviewer will be satisfied go for implementation.
Note: Do not implement solution without discussing it with the interviewer because it will be definetly a Red Card and you will be out
Round 3: This was final round and was taken by a Manager. First, he introduced himself and then asks me to introduce myself. After that, he directly jump to problem-solving and asks me 2 coding questions
- Give a 2D array of 1’s and 0’s, where 1denotes a person and 0 denotes a empty cell, find the minimum number of persons needs to be evacuated such that we can stop the spread of covid and maintain social distancing. If two 1’s are adjacent to each other column-wise or row-wise remove one of them and diagonally adjacent 1’s need not to be removed
Example: 1 1 0 1 1 1 1 1 1 Output: 0 1 0 1 0 1 0 1 0
- Given a page of a book, cursor position, and a keyword, return top k words near to the cursor which contains keyword as a substring. I was able to solve only 2nd problem.
Then we discuss the projects that I have mentioned in my resume.
So, be always prepared with whichever thing you have written on your resume, read about Amazon’s Leadership Principles, and do practice coding problems as much as you can.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course. In case you are prepared, test your skills using TCS, Wipro, Amazon and Microsoft Test Serieses.