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

SDE - 1

Amazon
upvote
share-icon
4 rounds | 8 Coding problems

Interview preparation journey

expand-icon
Journey
I did my graduation from Jaypee Institue Of Information Technology, Noida. During college time, when I was first introduced to coding, it felt like a really big thing to me. I had my ups and downs while learning it. But trust me the first step is the hardest , once I got comfortable onto solving questions, I developed a lot of interest for coding and I started giving lot of competitive programming contests on multiple coding platforms. This helped me a lot to improve my thinking ability and solve problems quickly. I was able to crack Hashedin and Amazon in college and I joined Amazon as an SDE.
Application story
Amazon was invited by our pre-placement cell. The only filter that Amazon had was the cgpa should be > 7. I registered using the link that was provided to us by Amazon. We were provided with a tentative date when Amazon would be visiting our college to conduct placement drive.
Why selected/rejected for the role?
I was confident during my interviews. I was speaking out loud whatever I was thinking. I wrote neat and clean and very descriptive code, with comments wherever needed. Writing re-usable code.
Preparation
Duration: 6 months
Topics: Data Structures, Algorithms , OOPS, Dynamic Programming, DBMS, computer networks.
Tip
Tip

Tip 1 : Consistency is the key, practice atleast 1 question daily.
Tip 2 : Focus on the quality of questions over the quantity of questions.
Tip 3 : Practice in time bound frame. Make sure you beat your time next time you solve the same question.

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

Tip 1: Add atleast 2 projects, one minor and one major. Know every detail about the project you've added to your resume. Focus on the quality of projects and not the quantity. Don't copy any project, add your originality to the project.
Tip 2: Make sure you add expertise level in front of each skill you mention in your resume. This would give the interviewer an idea of how much knowledge you have about a certain skill.

Interview rounds

01
Round
Medium
Online Coding Test
Duration120
Interview date8 Nov 2019
Coding problem3

All the college students were made to sit in college computer labs in the morning time. The round was of 120 minutes. We were provided with pen and paper and there were amazon employees who were there to assist. The round consisted of Code debugging, Aptitude, reasoning OOPs, DBMS, Operating Systems, Computer networks questions and 3 coding questions.

1. Write program to calculate pow(x, n)

Easy
15m average time
80% success
0/40
Asked in companies
AmazonQuikrPayPal

Given two integers x and n, write a function to compute xn. We may assume that x and n are small and overflow doesn’t happen.

Input : x = 2, n = 3

Output : 8

Input : x = 7, n = 2

Output : 49

Problem approach

A straightforward approach that I tried was compute pow(x, n) involves multiplying x by itself n times. This can be achieved efficiently using a basic for loop. But it would fail time constraints. 

Employing the Divide and Conquer strategy:
To address the problem, adhere to the following approach:

The problem can be recursively defined as follows:

power(x, n) = power(x, n / 2) * power(x, n / 2); // if n is even
power(x, n) = x * power(x, n / 2) * power(x, n / 2); // if n is odd
And we compute power(x, n / 2) only once. This was the optimised solution O(logN) which passed the tests.

Try solving now

2. Minimum time required to rotten all oranges

Moderate
20m average time
78% success
0/80
Asked in companies
Samsung R&D InstituteSalesforceSamsung

Given a matrix of dimension M * N, where each cell in the matrix can have values 0, 1 or 2 which has the following meaning: 

 0: Empty cell

1: Cells have fresh oranges

2: Cells have rotten oranges

The task is to the minimum time required so that all the oranges become rotten. A rotten orange at index (i,j ) can rot other fresh oranges which are its neighbors (up, down, left, and right). If it is impossible to rot every orange then simply return -1.

Examples: Input:  arr[][C] = { {2, 1, 0, 2, 1}, {1, 0, 1, 2, 1}, {1, 0, 0, 2, 1}};

Output: 2

Explanation: At 0th time frame:

{2, 1, 0, 2, 1}

{1, 0, 1, 2, 1}

{1, 0, 0, 2, 1}

At 1st time frame:

{2, 2, 0, 2, 2}

{2, 0, 2, 2, 2}

{1, 0, 0, 2, 2}

At 2nd time frame:

{2, 2, 0, 2, 2}

{2, 0, 2, 2, 2}

{2, 0, 0, 2, 2}

 

Problem approach

Brute force - Traverse through all oranges in successive rounds. During each round, move the oranges to adjacent positions of those that became rotten in the previous round. But this would fail the time complexity.

Optimised - The concept employs Breadth First Search (BFS) to track the rotting oranges. Oranges become rotten upon contact with other rotten oranges. This resembles a BFS strategy where the graph is organized into layers or cycles, and the search progresses from lower to higher layers.

In the earlier method, although BFS was utilized in concept, the execution was suboptimal and inefficient. Identifying the elements necessitated traversing the entire matrix. By adopting this more efficient BFS approach, time can be significantly minimized.

Try solving now

3. Pair sum is closest to x

Moderate
30m average time
70% success
0/80
Asked in companies
AmazonMicrosoftAcko

Given a sorted array and a number x, find a pair in an array whose sum is closest to x.

Examples:

Input: arr[] = {10, 22, 28, 29, 30, 40}, x = 54

Output: 22 and 30

Input: arr[] = {1, 3, 4, 7, 10}, x = 15

Output: 4 and 10

 

Problem approach

Brute force - A straightforward approach involves examining each pair and monitoring the pair with the smallest absolute difference between their sum and x. Subsequently, the closest pair is printed. The time complexity of this method amounts to O(n^2).

Binary Search Approach:- A more efficient solution compared to the previous approach involves utilizing Binary Search, leveraging the fact that the given array is sorted.

Try solving now
02
Round
Medium
Face to Face
Duration60
Interview date18 Nov 2019
Coding problem2

This round was a core coding interview round with the interviewer. It was meant to test how good is the candidate in problem solving and optimising solutions.

1. Count distinct elements in every window of size k

Moderate
15m average time
85% success
0/80
Asked in companies
HSBCZSCIS - Cyber Infrastructure

Given an array of size N and an integer K, return the count of distinct numbers in all windows of size K. 

Examples: 

Input: arr[] = {1, 2, 1, 3, 4, 2, 3}, K = 4

Output: 3 4 4 3

Explanation:  First window is {1, 2, 1, 3}, count of distinct numbers is 3                             

                     Second window is {2, 1, 3, 4} count of distinct numbers is 4                         

                     Third window is {1, 3, 4, 2} count of distinct numbers is 4                          

                     Fourth window is {3, 4, 2, 3} count of distinct numbers is 3

Input: arr[] = {1, 2, 4, 4}, K = 2

Output: 2 2 1

Explanation: First window is {1, 2}, count of distinct numbers is 2 

                     First window is {2, 4}, count of distinct numbers is 2  

                     First window is {4, 4}, count of distinct numbers is 1 

 

Problem approach

Brute force -Iterate through the given array, examining each window of size K, and tally the distinct elements within each window. Time complexity was O(N * K2) and interviewer told me to further optimise it.

Optimised using hashing - Count distinct numbers in all windows of size K using hashing. 
I was able to solve the problem in O(N) time and O(N) space and interviewer was satisfied.

Try solving now

2. Find Median from Running Data Stream

Moderate
20m average time
76% success
0/80
Asked in company
Amazon

Given that integers are read from a data stream. Find the median of elements read so far in an efficient way. 

There are two cases for median on the basis of data set size.

If the data set has an odd number then the middle one will be consider as median.

If the data set has an even number then there is no distinct middle value and the median will be the arithmetic mean of the two middle values.

Example:

Input Data Stream: 5, 15, 1, 3

Output: 5, 10,5, 4

Explanation: After reading 1st element of stream – 5 -> median = 5

                   After reading 2nd element of stream – 5, 15 -> median = (5+15)/2 = 10

                   After reading 3rd element of stream – 5, 15, 1 -> median = 5

                   After reading 4th element of stream – 5, 15, 1, 3 -> median = (3+5)/2 = 4

 

Problem approach

I gave the very brute force solution first using Insertion Sort. It's time complexity was O(n2), space O(1).

The interview asked me to further optimise it.

So I gave him the solution using 2 heaps , a min heap and a max heap. The interviewer was satisfied with the solution and asked me to write code for the same. Time complexity O(n*logn) , space - O(n)

Try solving now
03
Round
Hard
Face to Face
Duration60
Interview date18 Nov 2019
Coding problem2

1. Find the product of the maximum product subarray

Moderate
25m average time
75% success
0/80
Asked in companies
InnovaccerAmazonMicrosoft

Given an array that contains both positive and negative integers, the task is to find the product of the maximum product subarray.

 Examples:

Input: arr[] = {6, -3, -10, 0, 2}

Output:  180

Explanation: The subarray is {6, -3, -10}

Input: arr[] = {-1, -3, -10, 0, 60}

Output:   60

Explanation: The subarray is {60}

Problem approach

I started with a brute force solution by traversing over every contiguous subarray, finding the product of each of these subarrays and returning the maximum product from these results. Time was O(N^2) and interviewer asked me to optimise it.

Then I gave an optmised solution using Kadane’s algorithm and maintain 3 variables max_so_far, max_ending_here & min_ending_here. Iterate the indices 0 to N-1 and update the variables such that:

max_ending_here = maximum(arr[i], max_ending_here * arr[i], min_ending_here[i]*arr[i])
min_ending_here = minimum(arr[i], max_ending_here * arr[i], min_ending_here[i]*arr[i])
update the max_so_far with the maximum value for each index.
return max_so_far as the result.

The TC for this was reduced to O(N).
The interviewer was happy with this solution and asked me to write neat code for it.

Try solving now

2. LRU Cache

Moderate
25m average time
65% success
0/80
Asked in companies
MicrosoftUberSalesforce

Design a data structure that follows the constraints of a Least Recently Used (LRU) cache.

Implement the LRUCache class:

LRUCache(int capacity) Initialize the LRU cache with positive size capacity.int get(int key) Return the value of the key if the key exists, otherwise return -1.

void put(int key, int value) Update the value of the key if the key exists. Otherwise, add the key-value pair to the cache. If the number of keys exceeds the capacity from this operation, evict the least recently used key.

The functions get and put must each run in O(1) average time complexity.

 

Problem approach

I used Hashmaps & DLL(Doubly Linked List) to solve this.

Intuition:

While inserting the {key,val} pair into the DDL make sure that we are inserting it from the back tail to head.

The cache will tell us when the {key, value} pair is used/inserted.

Try solving now
04
Round
Easy
HR Round
Duration20
Interview date18 Nov 2019
Coding problem1

I was asked general questions, related to my future ambitions and how I would contribute to the company.

1.

Problem approach

Tip 1: Just be honest.
Tip 2: Read about Aamzon's leadership principles.
Tip 3: Don't try to fake anything. The Interviewer is more intelligent than you :)

Here's your problem of the day

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

Skill covered: Programming

How do you remove whitespace from the start of a string?

Choose another skill to practice
Similar interview experiences
company logo
SDE - 1
3 rounds | 5 problems
Interviewed by Amazon
0 views
0 comments
0 upvotes
company logo
SDE - 1
3 rounds | 5 problems
Interviewed by Amazon
3085 views
0 comments
0 upvotes
company logo
SDE - 1
4 rounds | 8 problems
Interviewed by Amazon
2295 views
1 comments
0 upvotes
company logo
SDE - 1
3 rounds | 6 problems
Interviewed by Amazon
1593 views
0 comments
0 upvotes
Companies with similar interview experiences
company logo
SDE - 1
4 rounds | 5 problems
Interviewed by Microsoft
58238 views
5 comments
0 upvotes
company logo
SDE - 1
4 rounds | 8 problems
Interviewed by Samsung
12649 views
2 comments
0 upvotes
company logo
SDE - 1
4 rounds | 8 problems
Interviewed by Microsoft
5984 views
5 comments
0 upvotes