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

Software Developer

Amazon
upvote
share-icon
2 rounds | 4 Coding problems

Interview preparation journey

expand-icon
Preparation
Duration: 6 months
Topics: Data Structures, Algorithms, System Design, Aptitude, OOPS
Tip
Tip

Tip 1 : Must do Previously asked Interview as well as Online Test Questions.
Tip 2 : Go through all the previous interview experiences from Codestudio and Leetcode.
Tip 3 : Do at-least 2 good projects and you must know every bit of them.

Application process
Where: Referral
Eligibility: Above 7 CGPA
Resume Tip
Resume tip

Tip 1 : Have at-least 2 good projects explained in short with all important points covered.
Tip 2 : Every skill must be mentioned.
Tip 3 : Focus on skills, projects and experiences more.

Interview rounds

01
Round
Medium
Face to Face
Duration60 minutes
Interview date18 Sep 2017
Coding problem2

Interviewer was mainly focused on problem solving skill.

1. Median of two sorted arrays

Hard
25m average time
65% success
0/120
Asked in companies
GrabMicrosoftWells Fargo

Given two sorted arrays 'a' and 'b' of size 'n' and 'm' respectively.


Find the median of the two sorted arrays.


Median is defined as the middle value of a sorted list of numbers. In case the length of list is even, median is the average of the two middle elements.


The expected time complexity is O(min(logn, logm)), where 'n' and 'm' are the sizes of arrays 'a' and 'b', respectively, and the expected space complexity is O(1).


Example:
Input: 'a' = [2, 4, 6] and 'b' = [1, 3, 5]

Output: 3.5

Explanation: The array after merging 'a' and 'b' will be { 1, 2, 3, 4, 5, 6 }. Here two medians are 3 and 4. So the median will be the average of 3 and 4, which is 3.5.
Problem approach

The most basic approach is to merge both the sorted arrays using an auxiliary array. The median would be the middle element in the case of an odd-length array or the mean of both middle elements in the case of even length array.
The merging of two sorted arrays can be done in a way similar to merge sort. The time complexity of this approach would be O(n+m). 
A better solution is to use binary search. 


Steps :
 

1. Find the length of the smaller arrays of the two. Perform binary search on the smaller array.
 

2. Initialize two pointers - start = 0 and end = m (assuming m is the smaller length).
 

3. Run a while loop : while (start <= end) { ... }.
 

4. Calculate the partition index (partitionA) for a which is the mid-point of start and end i.e., (start + end) / 2.
 

5. Calculate the partition index (partitionB) for b which is (m + n + 1) / 2 - partitionA.
 

6. Find the maximum element in the left of a and b and minimum element in the right of a and b.
Now, we can have three cases -
(i) If (maxLeftA <= minRightB && maxLeftB <= minRightA), then return the median based on (m + n) is even or odd.
(ii) Else If (maxLeftA > minRightB), it means, we need to go on the left, so, set end = partitionA - 1.
(iii) Else, we need to go to the right, so, set start = partitionA + 1.

Try solving now

2. Search in Sorted Rotated Array

Moderate
30m average time
65% success
0/80
Asked in companies
InformaticaDelhiveryGoldman Sachs

Aahad and Harshit always have fun by solving problems. Harshit took a sorted array consisting of distinct integers and rotated it clockwise by an unknown amount. For example, he took a sorted array = [1, 2, 3, 4, 5] and if he rotates it by 2, then the array becomes: [4, 5, 1, 2, 3].

After rotating a sorted array, Aahad needs to answer Q queries asked by Harshit, each of them is described by one integer Q[i]. which Harshit wanted him to search in the array. For each query, if he found it, he had to shout the index of the number, otherwise, he had to shout -1.

For each query, you have to complete the given method where 'key' denotes Q[i]. If the key exists in the array, return the index of the 'key', otherwise, return -1.

Note:

Can you solve each query in O(logN) ?
Problem approach

This was a pretty standard Binary Search Question and I had solved this question before on platforms like LeetCode and CodeStudio . I was asked this question to test my implementation skills and how well do I handle Edge Cases .

Approach :


1) The idea is to find the pivot point, divide the array in two sub-arrays and perform binary search.


2) The main idea for finding pivot is – for a sorted (in increasing order) and pivoted array, pivot element is the only element for which next element to it is smaller than it.
 

3) Using the above statement and binary search pivot can be found.
 

4) After the pivot is found out divide the array in two sub-arrays.
 

5) Now the individual sub – arrays are sorted so the element can be searched using Binary Search.

TC : O(Log(N))
SC : O(1)

Try solving now
02
Round
Medium
Face to Face
Duration45 minutes
Interview date18 Sep 2017
Coding problem2

Technical Interview Round with questions on DSA.

1. Reverse a linked list

Moderate
15m average time
85% success
0/80
Asked in companies
WalmartHCL TechnologiesInfo Edge India (Naukri.com)

Given a singly linked list of integers. Your task is to return the head of the reversed linked list.

For example:
The given linked list is 1 -> 2 -> 3 -> 4-> NULL. Then the reverse linked list is 4 -> 3 -> 2 -> 1 -> NULL and the head of the reversed linked list will be 4.
Follow Up :
Can you solve this problem in O(N) time and O(1) space complexity?
Problem approach

This can be solved both : recursively and iteratively.
The recursive approach is more intuitive. First reverse all the nodes after head. Then we need to set head to be the final node in the reversed list. We simply set its next node in the original list (head -> next) to point to it and sets its next to NULL. The recursive approach has a O(N) time complexity and auxiliary space complexity.
For solving the question is constant auxiliary space, iterative approach can be used. We maintain 3 pointers, current, next and previous, abbreviated as cur, n and prev respectively. All the events occur in a chain.


1. Assign prev=NULL, cur=head .
 

2. Next, repeat the below steps until no node is left to reverse:
2.1. Initialize n to be the node after cur. i.e. (n=cur->next)
2.2. Then make cur->next point to prev (next node pointer).
2.3. Then make prev now point to the cur node.
2.4. At last move cur also one node ahead to n.
 

The prev pointer will be the last non null node and hence the answer.

Try solving now

2. Kth Largest Element In An Array

Moderate
10m average time
90% success
0/80
Asked in companies
BNY MellonHSBCPayPal

You are given an array consisting of 'N' distinct positive integers and a number 'K'. Your task is to find the kth largest element in the array.

Example:
Consider the array {2,1,5,6,3,8} and 'K' = 3, the sorted array will be {8, 6, 5, 3, 2, 1}, and the 3rd largest element will be 5.
Note:
1) Kth largest element in an array is the kth element of the array when sorted in non-increasing order. 

2) All the elements of the array are pairwise distinct.
Problem approach

To solve the question using a max heap, make a max heap of all the elements of the list. Run a loop for k-1 times and remove the top element of the heap. After running the loop, the element at top will be the kth largest element, return that. Time Complexity : O(n + klogn)
The question can also be solved using a min heap. 


Approach :
1. Create a min heap class with a capacity of k.


2. When the heap reaches capacity eject the minimum number. 
 

3. Loop over the array and add each number to the heap. 
 

4. At the end, the largest k number of elements will be left in the heap, the smallest of them being at the top of the heap, which is the kth largest number.


The time complexity for this solution is O(N*log(K)).

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

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

Choose another skill to practice
Similar interview experiences
company logo
Software Developer
4 rounds | 6 problems
Interviewed by Amazon
1081 views
0 comments
0 upvotes
company logo
Software Developer
3 rounds | 5 problems
Interviewed by Amazon
1147 views
0 comments
0 upvotes
company logo
Software Developer
2 rounds | 4 problems
Interviewed by Amazon
1033 views
0 comments
0 upvotes
company logo
Software Developer
3 rounds | 6 problems
Interviewed by Amazon
970 views
0 comments
0 upvotes
Companies with similar interview experiences
company logo
Software Developer
5 rounds | 14 problems
Interviewed by Microsoft
4029 views
1 comments
0 upvotes
company logo
Software Developer
6 rounds | 12 problems
Interviewed by SAP Labs
2912 views
0 comments
0 upvotes
company logo
Software Developer
4 rounds | 6 problems
Interviewed by SAP Labs
1075 views
0 comments
0 upvotes