Hello, today I’m going to share my SDE-1 interview Experience at Amazon. I hope you are doing good and this article will help you with your interview preparation.
Interview Process
- Profile Screening
- Coding Assessment
- Pre – Interview discussion
- Technical Round 1
- Technical Round 2
- Managerial Round
- HR discussion
Profile Screening
I have applied to the careers portal directly and that time amazon was hiring actively also. After a week of applying for the appropriate role. I have got an email invite for coding assessment, and have an 72 hour window to send it.
Coding Assessment
This round consist of 2 coding questions and 1 easy and 1 medium difficulty.
Question 1: Valid Palindrome 2
Question 2: Shortest distance two cells matrix grid
Technical Round 1
At the the start of the Interview, the interviewer clearly explained the structure of this round. There will be 1-2 question, and it will be of 45 minutes and shared some link to their internal editor. It is expected that I will be coming out with the working solution with Time Complexity and Space Complexity.
Question 1: Given a node in a binary tree, return all the node in the level where the given Node exists
Example1: key = 5 , output = [2,5]
Example2: key = 1 ,output = [1,4]
Solution : Since, we have to return all the node in the level. Also, need to find the level where the given node lies. For example 1: Key 5 lies in the level 2, and level 2 have [2,5].
Thought Process: keep 2 maps, first which holds the node Vs level. for this example Map1: {3:1 ; 2:2 ; 5:2 ; 1:3 ; 4:3}. The second map will contain level Vs all Node in that level. For example Map2: {1:[3] ; 2: [2,5] ; 3: [1,4]}. Then do the DFS/BFS call to populate those maps
public class Node {
int val;
Node left;
Node right;
Node(int val) {
this.val = val;
this.left = null;
this.right = null;
}
public List<Integer> getAllNodesForGivenKey(Node node, int key){
Map<Integer,Integer> nodeVsLevel = new HashMap<>();
Map<Integer,List<Integer>> levelVsNodes = new HashMap<>();
populateNodeVsLevel(node,0,nodeVsLevel,levelVsNodes);
int level = nodeVsLevel.get(key);
return levelVsNodes.get(level);
}
private void populateNodeVsLevel(Node node, int level, Map<Integer,Integer> nodeVsLevel,Map<Integer,List<Integer>> levelVsNodes){
if(node!=null){
// store the level of the node in Map 1
nodeVsLevel.put(node.val,level);
// Now store the current node in the appropriate level
if(levelVsNodes.containsKey(level)){
levelVsNodes.get(level).add(node.val);
}else{
List<Integer> nodes = new ArrayList<>();
nodes.add(node.val);
levelVsNodes.put(level,nodes);
}
populateNodeVsLevel(node.left,level+1,nodeVsLevel,levelVsNodes);
populateNodeVsLevel(node.right,level+1,nodeVsLevel,levelVsNodes);
}
}
public static void main(String[] args) {
Node root = new Node(1);
root.left = new Node(2);
root.right = new Node(3);
root.left.left = new Node(4);
root.left.right = new Node(5);
root.right.left = new Node(6);
root.right.right = new Node(7);
List<Integer> nodes = root.getAllNodesForGivenKey(root,7);
System.out.println(nodes);
}
}
Output: [4,5,6,7]
Time Complexity : O(n), Space Complexity: O(n)
After this, the interviewer asked follow up question that. Suppose, we have an set of keys as input. So, for that case also just call the function in a iteration and get the nodes appropriately.
Technical Round 2
Its also a coding round, as the same structure as above. The interviewer straight jumped to the question, its also a tree based question.
Question1: Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree
Input: a = 5, b = 1
Output: 3
Explanation: The LCA of nodes 5 and 1 is 3.
Input: a = 5, b = 4
Output: 5
Explanation: The LCA of nodes 5 and 4 is 5, since a node can be a descendant of itself according to the LCA definition.
Solution: Since we find any one of the node either a or b just return it. If we get both as not null means its my LCA.
class Solution {
public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
if(root==null||root==p||root==q){
return root;
}
TreeNode left=lowestCommonAncestor(root.left,p,q);
TreeNode right=lowestCommonAncestor(root.right,p,q);
if(left==null)return right;
if(right==null)return left;
return root
;
}
}
Time Complexity: O(n), Space Complexity: O(Height)
I first given them the brute force approach, and then this optimized one. So, after clearing both this technical round 3 days later my managerial round got scheduled.
Managerial Round
Okay, now the Hiring manager popped up to the call. It started with my basic introduction and the project which I was working upon. since I haven’t worked enough any on web services or any framework, I lacked that experience. After the basic introduction from me and his side, he given me a problem. Design an API to collect User information of different geographic regions and save to DB. Also, write the Db schema. Its kind of a LLD round, and I was not prepared at all.
Since, till that moment of my career I haven’t wrote a single API. While in TCS I was working on some GIS application, and just written code specific to that particular application itself. I just started with the solution and tried to gather more requirements. Somehow I managed to design the DB schema. But, to design the API, I didn’t have any clue how to do it. Within 20 -30 minutes, the round got ended. Deep down I knew where I lacked. I realized that “just DSA is not enough for me to crack any BIG tech companies”.
After a week I tried to get the feedback from the recruiter. As, expected didn’t got selected but one thing I liked about the ending process. He gave a detailed feedback where I lacked and what areas I need to improve. So, yeah I worked more on that improved my problem solving skills, as well as learned to build web applications.
One thing I learned is that even if I was not prepared. I still chose to go ahead with giving the interview. There are tons of things to learn, but only by giving enough interviews. You will manage to cut down on tasks. You will focus on the areas that really bring value to your learning. As per my experiences till today after giving 5-10 interviews. You will find your own pattern of how questions get repeated and you will nail your next INTERVIEW ROUNDS!!!.
That’s all for today folks, see you on the next articles….. Happy Coding !!!….
Pingback: Kotak Mahindra Interview Experience SDE-1 - SEV7EN