# Amazon Interview Experience for SDE | Off-Campus (1-1.5 year experienced)

Round 1 (Online coding Round): This round was held on Amcat. There were 2 coding questions.

1. Given the 2D matrix. Each cell has a value 0 or 1. 1 represents land and 0 represents water. Find the Number of islands.
Example:

```Input:  1 1 0
0 1 0
Output: 2
0 0 1```

Approach: DFS in 2D matrix and take a count of how many times you have to do DFS to cover all 1’s.

2. You have an array of logs.  Each log is a space-delimited string of words. For each log, the first word in each log is an alphanumeric identifier. Then, either:

Each word after the identifier will consist only of lowercase letters, or;

• Each word after the identifier will consist only of digits.
• We will call these two varieties of logs letter-logs and digit-logs.  It is guaranteed that each log has at least one word after its identifier.

Reorder the logs so that all the letter-logs come before any digit-log.  The letter-logs are ordered lexicographically ignoring identifiers, with the identifier used in case of ties.  The digit-logs should be put in their original order.

```logs = ["dig1 8 1 5 1",
"let1 art can","dig2 3 6",
"let2 own kit dig",
"let3 art zero"]
Output: ["let1 art can",
"let3 art zero",
"let2 own kit dig",
"dig1 8 1 5 1",
"dig2 3 6"]```

Approach: Separate letter log and numeric log. Then sort letter log using own comparator then merge letter log and numeric log. After solving these questions there is a section where I have to write the approach in words and have to write time and space complexity. After that, there was a work-life survey and feedback survey section. After this round, I got the mail that I cleared the online coding round and wait until further communication.

After some weeks I got the mail and schedule three rounds of interviews in one day.

Round 2 (online on Amazon Chime): The first interviewer introduces herself then I introduce myself. Then She asked me two coding questions.

1. One array is given with size N each index has one value >=0. This value represents how many maximum steps I  can go further. I have to find a number of ways to reach the end of an array. If not possible then return -1.

```Input: 1 2 1 4
Output: 2```

Explanation: arr = 1 so, I can only go to index 1
arr = 2 so, from here I can go to index 2nd and 3rd.
arr = 1 from here I can go to index 3rd.
possible paths to reach at the end of the array: 0->1->2->3
0->1->3

Approach: Start from the end and go to the indexes which are possible to go from the current index and take the sum of the number of ways to reach the end from that index. Do it of all indexes from right to left and you will get the number of ways to reach at the end of the array.

```Input: 1 2 1 4
Output: 2 2 1 1```

Explanation:

• For 3rd index: it already ends so set as 1
• 2nd index: arr = 1 so, take the sum of index 3 from the answer and update the answer array ans = 1
• 1st index: arr =2 so, take the sum of the index  2 and 3  from answer array ans = 2
• 0th index: arr =1 so, take the sum of index 1st from answer array. ans = 2;
• At the end return ans;
• Edge case N=1 return 0.
• Time complexity: O(n^2);
2. Given two values l and r. I have to find special numbers between l to r. Special Number: adjacent digit has an exact absolute difference of 1 special number: 10, 12, 21, 23

So, first I gave a brute force approach. Traverse l to r and check number is a special number or not. This approach takes time complexity O(n*(number of digits)). So, she asked me to optimize more. So, I gave some different approaches and in the end, I gave her a queue approach to solving this problem.

Round 3 (online on Amazon Chime): In this round interviewer asked me 3 coding questions and some behavioral questions. It starts with my and interviewer’s quick introduction.

1. There is a 2d matrix of size NxM. Each cell has a positive value. from each cell, I can go only to diagonally right down or diagonally right up. I have to find the maximum sum path from the first column cell to the last column cell.  I gave the O(n^2) approach and she was satisfied with that.

## C++

 `int` `solution(vector > arr, ``int` `n, ``int` `m) ` `{ ` `    ``int` `dp[n][m]; ` ` `  `    ``memset``(dp, ``sizeof``(dp), -1); ` `    ``int` `ans = 0; ` `    ``for` `(``int` `col = 0; col < m; col++) { ` `        ``for` `(``int` `row = 0; row < n; row++) { ` `            ``int` `temp = 0; ` `            ``if` `(row - 1 >= 0 && col - 1 >= 0) ` `                ``temp = max(temp, dp[row - 1][col - 1]); ` `            ``if` `(row + 1 < n && col - 1 >= 0) ` `                ``temp = max(temp, dp[row + 1][col - 1]) ` ` `  `            ``dp[row][col] = arr[row][col] + temp; ` `            ``ans = max(ans, dp[row][col]); ` `        ``} ` `    ``} ` ` `  `    ``return` `ans; ` `}`

2. One array is given of size n. n is always even. There are two players A and B.  For each turn, one player can take an element from the start or the end of the array. If a player takes one of the elements then it adds to the sum of that player and removes it from the array. Both players are playing optimally.  I have to find the maximum sum achieve by player A.

First I gave to exponential approach using recursion the add memorization in it and make the top-down approach of DP.  She was satisfied with my approach.

This is a similar question: https://www.geeksforgeeks.org/optimal-strategy-for-a-game-dp-31/

3. There is an array of string. All the string in the array is in camel case. The abbreviation of each string will be the capital letters of that string.

I have to make API that where input is as an abbreviation and have to return all strings in which abbreviation has input abbreviation as a prefix.

Example:

```String array:
GoodMorning
Good
GoodNight
LightHouse
Abbreviation of the above strings will be:
GM
G
GN
LH
Query:
Input: G
Output: GoodMorning, Good, GoodNight
Input: GM
Output: GoodMorning```

For this question, I gave two approaches. First using a map. Where I store the key as a prefix of an abbreviation and value as a vector of string which has this key as a prefix in its abbreviation.
The second approach I gave to use Trie Data structure. She asked me to implement a map approach and write space and time complexity.

After that, she asked some behavioral questions which are base on amazon leadership principles. This interview lasts around one and a half hours.

Round 4 (online on Amazon Chime): This interview was completely based on amazon leadership principles. The interview starts with my and interviewer’s quick introduction. He asked about some situations which face in my current company and how I handle it and what was the outcome of that. This round was more interactive round. He asked me 2 small questions. First was what is thread and process and the difference between them.  Then he asked me to explain hashmap and hashtable. I know that hashmap and hashtable is a concept of JAVA and my complete experience was C++. So he asked me to explain the difference between a map and an unordered map and its internal working. This interview lasts around 40 min.

After 2 weeks of 3rd round, I got the mail and set 4th round with Software Development Manager.

Round 5 (Bar Raiser)(online on Amazon Chime): The interviewer was Software Development Manager, and he had 9 years of experience on amazon. The interview starts with my and interviewer’s quick introduction.

1. There is one small toy shop which can contain Maximum X toys. The shop owner has contracted with a toy company that gave supply to the owner on a time basis. So, at one time when new toys arrived, it is possible that the total toys increased more than the limit X. So, the owner has to remove those toys which come first in the shop. The owner has the previous year selling data which shows how many time-specific toys were sold.

I have to make a data structure for two queries.

• When new toys arrived and the limit exceeds X then which toys will be removed.
• Return max sold toy from last year’s data. But that toy should be present in the shop.

For the first query, I suggest deque and map data structure and for the second query, I suggest a map and max_heap data structure. We discuss this approach, and he was satisfied with my answer.

2. He asked me one coding question. There is one binary tree. I have to update the binary tree node value to the sum of the right subtree. Leaf nodes should be as it is.

```Input                   Output
1                       16
2  3                   5    7
4 5 6 7                4  5 6 7

```

## C++

 `int` `solution(Node* root){ ` `    ``if``(root == NULL) ``return``; ` `       `  `      ``if``(root->left==NULL && root->right==NULL) ` `          ``return` `root->data; ` `   `  `      ``int` `left_sum = solution(root->left); ` `      ``int` `right_sum = solution(root->right); ` `   `  `      ``int` `temp = root->data; ` `     `  `      ``root->data = right_sum; ` `       `  `    ``return` `left_sum + temp + right_sum;  ` `} `

He asked me some behavioral questions based on amazon’s leadership principles. We had a healthy discussion on every question. For each behavioral question, I have to explain the situation and each situation connects with the present company’s project.  He asked many queries and we discuss that.

After some days I got the mail that I’m selected for the SDE-1 profile 🙂

Tips:

• Be interactive,  as much as possible with the interviewer.  If you don’t know the solution to the question then tell the interviewer in which way you are thinking. Interviewers are very helpful if you interact with them they will guide you to the solution.
• Write clean and production-ready code and cover all edge cases. The interviewer checks your solution with test cases.
• First, give the brute force approach and then move to the optimized approach. For each question, they want an optimized solution

Thanks, GeeksforGeeks. It helped me a lot in preparation.

Best of Luck…

Write your Interview Experience or mail it to contribute@geeksforgeeks.org My Personal Notes arrow_drop_up

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

5

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.