Hi all, Amazon conducted a pool drive in January 2019 in Gurugram. We were shared a link for the test hosted on HackerEarth. The pattern of the test was 20 MCQ’s and 2 Programming Questions.
20 MCQ’s based on OS, Network, COA, DBMS, OOPS.
Q1: Given a NxM Grid. The grid consists of only 3 integers(0, 1, 2)
- 0 denotes empty cell.
- 1 denotes a cell containing plant.
- 2 represents a cell where you are standing currently.
You can move to adjacent cells (Up, Down, Left, Right). Find the length of the shortest path to reach one of the boundaries without stepping on a plant.
Length of the path is the number of moves you make.
Q2: You are given some rules (<=26) an integer K.You can make several permutations of the rules while keeping the given rules fixed.
Write a program to find the Kth lexicographically smallest permutations of the rules.
Alphabets b, c, d have already been mapped to be represented x, y, z respectively. Now we need to find the lexicographically smallest (K=1) permutation of the alphabet. This is done if we assign each remaining alphabet to the earliest possible position in the permutation. Hence, the answer is axyzbcdefghijklmnopqrstuvwxyz.
I got the first question complete and the second question partial which was enough to qualify for the face to face interview.
I answered them both.
The interviewer first asked me to think of the approach and explain that approach to him.Once he was satisfied with the approach, He asked me to write production level code.
Q1: Given a list of IP addresses [126.96.36.199, 188.8.131.52, … ]. Remove duplicate IP’s in the list.
Sol: I gave the first answer that store the IP addresses in a set while iterating and if IP is found in set, remove it.
However, Interviewer wasn’t satisfied with the space complexity so he told me to reduce the space complexity.
I came up with a tries based solution where instead of storing an IP in set, I store it in Trie.(Space complexity is reduced as Node in Trie doesn’t take up space unless allotted a value as well as instead of creating a new node for every IP, in Trie a node can be reused if even half of the IP is same).
Q2: Maximum path sum
(Without Space Complexity)
Solved the first question completely but took more time, so couldn’t solve the second question on time.
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.