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

SDE - 1

Amazon
upvote
share-icon
5 rounds | 12 Coding problems

Interview preparation journey

expand-icon
Journey
I started my journey in coding from second year after being motivated from my seniors. I initially started my journey by learning basic programming languages. Later, I started giving contests on code forces and solving questions on it. I kept trying to be consistent in doing so. After 2-3 months I was able to solve some questions on code forces. Then in my third year, I studied core subjects like OS, DBMS, OOPS and CN in depth. In this manner, I was well prepared before the placement season.
Application story
I got this opportunity through campus placements. Amazon visited our campus for internships and placements. I applied through my resume on their portal.
Why selected/rejected for the role?
I was able to solve almost all the questions asked me during the selection process. I have done a lot of coding practise on Competitive programming sites and built a deep understanding of programming skills. My good communication skills are also one reason of my selection.
Preparation
Duration: 8 months
Topics: Data Structures and Algorithms, Operating System, Database Management System, Object-Oriented Programming System
Tip
Tip

Do lot of hard work and practice of  Data Structures and Algorithms based questions. I personally recommend you Coding Ninjas and Geeks For Geeks for interview preparation.

Application process
Where: Campus
Eligibility: 7 CGPA
Resume Tip
Resume tip

Make your resume short and try to make it of one page only and do mention all your skills which you are confident of in your resume.

Interview rounds

01
Round
Easy
Online Coding Test
Duration60 minutes
Interview date25 Jan 2019
Coding problem2

1. Tiling Problem

Hard
45m average time
0/120
Asked in companies
OlaOptumFlipkart

Given a “2 x n” board and tiles of size “2 x 1”, count the number of ways to tile the given board using the 2 x 1 tiles. A tile can either be placed horizontally i.e., as a 1 x 2 tile or vertically i.e., as 2 x 1 tile.

Examples:

 

Input n = 3

Output: 3

Explanation:

We need 3 tiles to tile the board of size  2 x 3.  

We can tile the board using following ways

1) Place all 3 tiles vertically.  

2) Place first tile vertically and remaining 2 tiles horizontally.

3) Place first 2 tiles horizontally and remaining tiles vertically

 

Input n = 4

Output: 5

Explanation:

For a 2 x 4 board, there are 5 ways

1) All 4 vertical

2) All 4 horizontal

3) First 2 vertical, remaining 2 horizontal

4) First 2 horizontal, remaining 2 vertical

5) Corner 2 vertical, middle 2 horizontal

Problem approach
  • I have done this problem earlier so got the DP based approach during the test and this approach passed all the test cases.
Try solving now

2. Find k’th character of decrypted string

Moderate
33m average time
0/80
Asked in companies
SamsungSiemensSwiggy

Given an encoded string where repetitions of substrings are represented as substring followed by count of substrings. For example, if encrypted string is “ab2cd2” and k=4 , so output will be ‘b’ because decrypted string is “ababcdcd” and 4th character is ‘b’.

 

Note: Frequency of encrypted substring can be of more than one digit. For example, in “ab12c3”, ab is repeated 12 times. No leading 0 is present in frequency of substring.

 

Examples:

 

Input: "a2b2c3", k = 5

Output: c

Decrypted string is "aabbccc"

 

Input : "ab4c2ed3", k = 9

Output : c

Decrypted string is "ababababccededed"

 

Input: "ab4c12ed3", k = 21

Output: e

Decrypted string is "ababababccccccccccccededed"

Problem approach

 I simply decrypt the string by reading substring and their frequency and append current substring to the decrypted string and after the end of traversal of given string our answer will be kth element of the decrypted string.

Try solving now
02
Round
Easy
Face to Face
Duration50 minutes
Interview date25 Jan 2019
Coding problem2

1. Count Positive-Negative Pairs

Easy
22m average time
0/40
Asked in companies
AmazonAtlassianAmdocs

Given an array of positive and negative integers, print x if +x and -x are present in the array. 

Problem approach

I asked for some clarifications whether I should print all distinct x‘s or if I should print an x if a pair of +x and -x is encountered. The first approach I told was to use a map and I was keeping a flag for +x and -x if it’s found once. Later he asked me to print all pairs, so I stored the frequencies of all the elements in the map and iterated through the negative elements and for each element x , I would print x min(count[-x],count[+x]) times. He said he can’t afford that much space and he wanted me to optimise space further. So I told him a 2 pointer approach where I sort the array once and then keep two pointers to the start and end. I would move the start pointer forward if the sum is less than 0 and I’ll move the end pointer backward if the sum is greater than 0. He was fine with the solution and asked me to code it in a paper. I wrote the code and walked him through it.

Try solving now

2. Design the logic for minimising cash flow in an app like ‘Splitwise’.

Problem approach

Here the interviewer told me about an app called splitwise which i had used once. In the application each user adds the amount he spends and it’s shared equally among users of the app. The aim is to minimise the number of give and take operations. I initially thought of a very naive approach where I wanted to create classes for each person and expenditure and iterate through the expenditures of other people to find how much a person should give or take. When I took a closer look I got the idea of modelling it as a directed graph and adding directed edges for transactions. With the graph I thought of taking the difference between the pair of edges between two people to reduce a give and take operation to a single give/take operation. There was a catch, if A has to give B Rs.10, B has to give C Rs.10, and A has to give C Rs.10, the minimum operation to do is to give Rs.20 from A to C. B is not involved here as he has to spend all he gets. So I said we could preprocess the graph with the numbers on the incoming and outgoing edges. If the total flow is 0, we could remove that node. He seemed convinced with the approach. He gave me a graph after all the preprocessing done and finally asked me how to minimise it. So I used a greedy method. I was settling the amount of the person who has to get the largest amount by giving the amount of the people who has to give lesser amounts and he said that’ll work.

03
Round
Easy
Face to Face
Duration60 minutes
Interview date25 Jan 2019
Coding problem2

At the beginning of this round, the interviewer asked me about the data structures I knew. Linked lists, trees, graphs, arrays etc. was my answer. He asked me how well I knew Dynamic Programming. I said I wasn’t strong in that and he said that he would ask me a question on dynamic programming for sure.

1. Count Special Nodes in Generic Tree

Hard
39m average time
0/120
Asked in company
Amazon

Given a generic tree, find the count of all special nodes. A node is a special node if there is a path from root to that node with all distinct elements. The input was not a pointer to a tree. He’d give me an adjacency list and an array of values where the value of ith node in the adjacency list is the ith element in the values array. He asked me not a create a tree out of the given information and rather do it with the adjacency list itself. 

Problem approach

I suggested to do a depth first search keeping a set which contains all elements upto a given node. Once I reach a particular node, I check if it’s already in the set. If its already in the set, I return because that element has already been visited and is not a special node. Otherwise, I increase the count of a global variable by 1 and push that element to the set. Then I go through the adjacency list of that element and call this function recursively. Once I return from the element after visiting its neighbors, I pop the element from the set. I told him the approach and he asked me to write the code for it. He was convinced with the approach and he liked the code.

Try solving now

2. Common Digit Longest Subsequence

Moderate
31m average time
0/80
Asked in companies
AmazonSamsungOptum

Given an integer array, find the longest subsequence with adjacent numbers having a digit in common. Eg: 1 12 44 29 33 96 89 . The longest subsequence here is { 1 12 29 96 89} and the answer is 5.

Problem approach

I initially tried a 2D DP solution where dp[i][j] indicates the length of the longest sequence with ending at i containing j as a digit. It’s a N X 10 DP matrix. The interviewer asked me why I needed a 2D DP solution and I struggled to convince him. I wrote the code for it. It wasn’t completely correct. I was missing something. After thinking for a while I narrowed down to a solution containing only 10 elements dp[0], dp[1], dp[2].. dp[9] which is updated every time I see a new number. I take a number, I go through all digits in the number and find value = 1 + max(dp[d] for all digits d in the number). Set this value to dp[d] for all digits in the number. He gave a hint to take the max and finally gave a solution to the interviewer and he was satisfied with that solution.

Try solving now
04
Round
Easy
Face to Face
Duration40 minutes
Interview date11 Feb 2019
Coding problem2

 

The interviewer asked me if I was comfortable with the interview process so far and how the previous interviews were. I said it was good and he gave me the first problem to solve.

1.

Given a binary tree, modify the tree satisfying the following constrains :

Value at root must be the sum of left child and right child (not subtrees).

You can’t reduce the value at any node. You can only increase it.

Value of root node must be minimum  

 

Problem approach

I drew a few trees and asked him the output for those examples. He asked me to say it myself and I did. I thought of doing a post-order traversal as we need to visit the root’s left and right child before visiting root. In the post-order traversal, we keep the sum of root’s left and right child in a variable sum. We take the difference of this sum and root data. If the sum is greater than root’s data, we replace the root with the sum. Otherwise, we have to distribute the root’s value to the root’s left and right child so that all the three conditions are satisfied. (We can’t reduce the value at any node). He asked me to write the code for it and I did. 

2. Sort 0 1 2

Easy
22m average time
0/40
Asked in companies
WalmartZS AssociatesIntuit

Given an array A of size N containing 0s, 1s, and 2s; you need to sort the array in ascending order. You can scan the array only once.

Problem approach

 I solved this question using three-pointers and this problem was a variation of dutch national flag problem. The interviewer was satisfied by my approach as this was the most optimal approach.  

 

Try solving now
05
Round
Easy
Face to Face
Duration60 minutes
Interview date11 Feb 2019
Coding problem4

The interviewer asked me some Com­puter Sci­ence‍ fundamentals in this round as well as some behavioural questions.

1. Difference between threads and processes.

Problem approach

This is most basic question of OS and I explained it very well using a tabular representation.

2. Deadlocks and its prevention.

Problem approach

I firstly told him necessary conditions for deadlock and then explained him that if we don’t let all conditions fulfilled for deadlock then it may be prevented.

3. Trie data structure

Hard
41m average time
0/120
Asked in companies
UberInfosysTata Consultancy Services (TCS)

Implement a Trie data structure and write functions to insert and search for a few words in it.

Problem approach

I wrote a class to implement a character Trie using a vector of nodes as children. He asked me to improve on space. So I used a hashmap to store the child nodes only if a child exists. I wrote the code for insertion and finding a word and walked him through.

 

Try solving now

4. Anagram Pairs

Moderate
30m average time
60% success
0/80
Asked in companies
CiscoThought WorksInfosys

Given two strings a and b consisting of lowercase characters. The task is to check whether two given strings are anagram of each other or not. An anagram of a string is another string that contains same characters, only the order of characters can be different. For example, “act” and “tac” are anagram of each other.

Problem approach

I implemented it first by sorting two strings and comparing them. He asked me to write a better approach. So I used a hashmap to do it.

Try solving now

Here's your problem of the day

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

Skill covered: Programming

Which collection class forbids duplicates?

Choose another skill to practice
Similar interview experiences
company logo
SDE - 1
3 rounds | 5 problems
Interviewed by Amazon
1406 views
0 comments
0 upvotes
company logo
SDE - 1
4 rounds | 8 problems
Interviewed by Amazon
1457 views
1 comments
0 upvotes
company logo
SDE - 1
3 rounds | 6 problems
Interviewed by Amazon
705 views
0 comments
0 upvotes
company logo
SDE - 1
4 rounds | 8 problems
Interviewed by Amazon
3069 views
0 comments
0 upvotes
Companies with similar interview experiences
company logo
SDE - 1
4 rounds | 5 problems
Interviewed by Microsoft
51680 views
5 comments
0 upvotes
company logo
SDE - 1
4 rounds | 8 problems
Interviewed by Samsung
11432 views
2 comments
0 upvotes
company logo
SDE - 1
2 rounds | 4 problems
Interviewed by Google
10121 views
0 comments
0 upvotes