Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding
Ninjas X Naukri.com

Amazon interview experience Real time questions & tips from candidates to crack your interview

Amazon

5 rounds | 9 Coding
problems

Journey

I joined a tier 3 college and worked hard to master DSA. I got placed in a startup initially. Along with my job, I used to practise DSA so that I can apply for product-based companies as well. Finally, I got a chance to apply for Amazon. I revised all the main DSA algorithms and gave some mock interviews in order to prepare well.

Application story

I started updating my resume and profile on Naukri.com due to which the companies started to contact me for the required jobs. Luckily my resume got shortlisted and was asked by the HR to go through the all the rounds.

Why selected/rejected for the role?

I was selected because I had in-depth understanding of DSA topics. Moreover, I knew everything that I had worked on in my previous company. So, I was able to answer all questions clearly and confidently.

Preparation

Duration: 7

Topics: Data Structures, Algorithms, OOPS, Graphs, Trees

Tip

Tip 1 : Start with the basics if you have lost touch with competitive coding. Don't directly jump to interview questions.

Tip 2 : Create a timetable and set goals. Keep aside 3-4 hours for studying. Consistency is the key.

Tip 3 : Focus on medium and hard questions. Solving a lot of easy questions doesn't help.

Application process

Where: Naukri

Eligibility: None

Resume tip

Tip 1 : You should have good projects to showcase.

Tip 2 : Keep it clean and simple.

01

Round

Easy

Online Coding Test

Duration90

Interview date6 Sep 2020

Coding problem2

Two coding questions were asked and 90 minutes of time was allotted to solve both the problems

```
We cannot use the element at a given index twice.
```

```
Try to do this problem in O(N) time complexity.
```

Problem approach

Sort the array and find the target sum with 2 pointer technique.

```
1. Coordinates of the cells are given in 0-based indexing.
2. You can move in 4 directions (Up, Down, Left, Right) from a cell.
3. The length of the path is the number of 1s lying in the path.
4. The source cell is always filled with 1.
```

```
1 0 1
1 1 1
1 1 1
For the given binary matrix and source cell(0,0) and destination cell(0,2). Few valid paths consisting of only 1s are
X 0 X X 0 X
X X X X 1 X
1 1 1 X X X
The length of the shortest path is 5.
```

Problem approach

Solved it using BFS. Created a queue. First added the source cell to the queue and distance as 0. In the loop(with loop being empty as terminating condition.), popped a cell and distance. Added its neighboring cells containing 1 or 3 and distance+1. Marked the cells as visited.

If the popped cell is the destination, then returned the distance.

02

Round

Medium

Video Call

Duration60

Interview date13 Sep 2020

Coding problem2

The duration was approx 1 hour. The interview was taken by a young SDE-2.

```
Given 'S' : abcdg
Then output will be : 1 1 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
```

```
1. Escape cells in this problem are all such cells that lie on the edge of the matrix but not on the corner. i.e all such cells which are in the first row, first column, last row, and last column excluding the four corner cells are considered as valid escape cells.
2. A cell once set on fire continues to remain on fire till the end.
3. Note that rows are indexed from 0 to ‘N’ - 1 and columns are indexed from 0 to ‘M’ - 1.
4. The escape cells may also be initially on fire or can catch fire from some neighboring cell.
```

Problem approach

Solved using BFS. Maintained 2 queues this time, one for fire cells and another for movement cells.

Returned True if the person reaches an edge cell. Mark each firing cell, visited cell, and movement cell as 0 so that it is not added to the movement queue going ahead. Initially added all the fire cells to the fire queue. In one iteration, add the possible safe cells to the movement queue and then add adjacent cells for the fire to fire queue. If the value of the cell popped from the movement queue is 0 then continue else explore its adjacent cells. Used concept of levels(extra loop for cells at a level) in BFS.

03

Round

Hard

Video Call

Duration60

Interview date13 Sep 2020

Coding problem2

The interviewer introduced himself and asked me to introduce myself.

I told him about the different projects that I had done and the work in the previous company.

I had worked on AWS(Amazon Web Services) so he asked me all the AWS services that I had worked with and to explain one of them.

I explained about the working of ECS(Elastic Container Service).

After this, he moved to the coding questions.

Here, the arrows starting from the 0-cell’s point towards their corresponding nearest one cell, and among all of these, the arrow in purple and orange gives the maximum distance, i.e., 2.

```
1) Binary matrix of size N*M is a matrix with N rows and M columns, in which all the cells have either value 0 or 1.
2) Nearest 1-cell from a 0-cell is the cell that contains 1 and is at least a distance from the 0-cell being considered among all the other cells. For example consider the matrix {{0,1},{0,1}}. Here the nearest 1-cell for the 0-cell at index(0,0) is the 1-cell at index (0,1) because this cell is at least distance from the 0-cell being considered as the distance from the other 1-cell at index(1,1) is 2, whereas the distance from the 1-cell at index (0,1) is 1.
3) If there are no 1-cells or no 0-cells in the matrix, return -1.
```

Problem approach

Solved using BFS. Initialize distances for all zeroes to be infinity. Add 0 cell to queue if the distance is less than the already calculated distance. Used extra loop for levels in BFS. When the queue gets empty, the last level gives the maximum distance

```
1) The array may contain duplicate elements.
2) The size of the array is at least 2.
3) The given array follows 0-based indexing so 0 <= i,j< N.
4) It is guaranteed that there exist at least one such pair of indices.
```

Problem approach

As we traverse the array, maintain another array that stores the last k elements in ascending order. Find the position of the current element in the sorted array and check the absolute difference between the preceding and next element. If the absolute difference is less than equal to t then return the two values. Remove element at i-k from sorted array.

Time Complexity: O( n log(k) ), where n is the length of the given array.

04

Round

Medium

Video Call

Duration60

Interview date17 Sep 2020

Coding problem1

The interviewer was a very senior person with at least 10-15 years of experience. He introduced himself and asked me to tell him about myself. (Leadership principle questions followed)

```
1. A binary tree is a tree in which each node can have at most two children.
2. The given tree will be non-empty i.e the number of non-NULL nodes will always be greater than or equal to 1.
3. Multiple nodes in the tree can have the same values, all values in the tree will be positive.
```

Problem approach

Solved using DFS. Similar to mirror trees. Pass root left and root right as arguments to the is _mirror_tree function. First explained the approach to the interviewer. He was satisfied and asked me to write code.

05

Round

Medium

Video Call

Duration60

Interview date28 Sep 2020

Coding problem2

The interview started with introductions and some Leadership principle questions. The interviewer was again a senior person with at least 10-15 years of experience.

I was asked to explain some AWS services.

He asked me to tell about a time when I had a tight deadline and how I worked during it.

He asked me about a time when I took initiative and came up with something new which helped the entire team.

I had prepared well for the LP questions and was able to answer everything.

After this, we move on to coding questions.

```
1. All the characters in the string and the word are in lowercase.
2. Length of the sentences and the words will always be greater than zero.
3. Words in the sentence will be separated by spaces.
```

Problem approach

Discussed the solution using the hash map. He was convinced and asked me to code. I wrote a well-commented code and he was happy with it.

```
1. get(key) - Return the value of the key if the key exists in the cache, otherwise return -1.
2. put(key, value), Insert the value in the cache if the key is not already present or update the value of the given key if the key is already present. When the cache reaches its capacity, it should invalidate the least recently used item before inserting the new item.
```

```
Type 0: for get(key) operation.
Type 1: for put(key, value) operation.
```

```
1. The cache is initialized with a capacity (the maximum number of unique keys it can hold at a time).
2. Access to an item or key is defined as a get or a put operation on the key. The least recently used key is the one with the oldest access time.
```

Problem approach

I had solved it earlier and explained to him the approach using doubly Linked List and Hash map.

He was convinced with my approach and asked me to code it without using any in-built data types. He asked me to write classes. I had prepared the solution with classes and started writing the code.

Here's your problem of the day

Solving this problem will increase your chance to get selected in this company

What does ROLLBACK do in DBMS?

Similar interview experiences

SDE - 1

3 rounds | 5 problems

Interviewed by Amazon

854 views

0 comments

0 upvotes

SDE - 1

4 rounds | 8 problems

Interviewed by Amazon

1138 views

1 comments

0 upvotes

SDE - 1

3 rounds | 6 problems

Interviewed by Amazon

441 views

0 comments

0 upvotes

SDE - 1

4 rounds | 8 problems

Interviewed by Amazon

1287 views

0 comments

0 upvotes

Companies with similar interview experiences

SDE - 1

4 rounds | 5 problems

Interviewed by Microsoft

49377 views

5 comments

0 upvotes

SDE - 1

4 rounds | 8 problems

Interviewed by Samsung

11000 views

2 comments

0 upvotes

SDE - 1

2 rounds | 4 problems

Interviewed by Google

9567 views

0 comments

0 upvotes

Thank you for giving tips for Preparation

Helpful