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

SDE - 1

Amazon
upvote
share-icon
2 rounds | 4 Coding problems

Interview preparation journey

expand-icon
Preparation
Duration: 6 months
Topics: C, C++, Java, Data Structures, Pointers, OOPS, System Design, Algorithms, Dynamic Programming, Low level design
Tip
Tip

Tip 1 : Must do Previously asked Interviews Questions from geeksforgeeks and codestudio.
Tip 2 : Prepare OS, DBMS, OOPs, Computer Networks well.
Tip 3 : Prepare well for one project mentioned in the resume, the interviewer may ask any question related to the project, especially about the networking part of the project.

Application process
Where: Referral
Eligibility: None
Resume Tip
Resume tip

Tip 1 : Have at least one project in the resume and mention your online coding profiles
Tip 2 : Must mention every skill and certificate in the resume.
Tip 3 : Must have known every strong and intermediate skill mentioned in resume.

Interview rounds

01
Round
Medium
Online Coding Test
Duration120 minutes
Interview date1 Jul 2022
Coding problem2

This was the online test held on the hackerrank consist of two coding questions based on array and string.

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

/*
Approach 1: Brute Force TC: O(n) SC: O(n)
1. We Merge The Two Sorted Array (Basic Merging Method Of Merge Sort, With 2 Pointers.
2. We Find The Median Of The New Array.
*/
class Solution {
public double findMedianSortedArrays(int[] nums1, int[] nums2) {

int nums1Pointer = 0;
int nums2Pointer = 0;
int numsPointer = 0;
int[] nums = new int[nums1.length + nums2.length];

while(nums1Pointer < nums1.length && nums2Pointer < nums2.length){
if(nums1[nums1Pointer] < nums2[nums2Pointer]){
nums[numsPointer] = nums1[nums1Pointer];
nums1Pointer++;
}else{
nums[numsPointer] = nums2[nums2Pointer];
nums2Pointer++;
}
numsPointer++;
}

while(nums1Pointer nums2.length){
return findMedianSortedArrays(nums2, nums1);
}

// Applying Binary Search To The 2 Arrays
int nums1Length = nums1.length;
int nums2Length = nums2.length;
int start = 0;
int end = nums1Length;

while(start <= end){

int partition1 = start + (end-start)/2; // Mid Partition In The Smaller Size Array
int partition2 = (nums1Length + nums2Length + 1)/2 - partition1; // Mid Partition In The Larger Size Array

// Taking Left And Right Values Of The Partition Of Both The Arrays And Cross Checking Them
int left1 = (partition1 > 0)? nums1[partition1 - 1] : Integer.MIN_VALUE;
int left2 = (partition2 > 0)? nums2[partition2 - 1] : Integer.MIN_VALUE;

int right1 = (partition1 < nums1Length)? nums1[partition1] : Integer.MAX_VALUE;
int right2 = (partition2 < nums2Length)? nums2[partition2] : Integer.MAX_VALUE;

/*
If Left Value Of The First Array Is Smaller Than Right Value Of The Second Array 
And
Left Value Of The Second Array Is Smaller Than Right Value Of The First Array
Then
We Check If The Size Of The Sum Of Length Of Both Arrays Is Odd Or Even Because
If Odd, We Return The Max Of Left1 And Left2, And If Even We Return The Average
Of (Max(left1, left2) + Min(right1, right2)) / 2.0 as per the Average Formula.
*/
if(left1 <= right2 && left2 <= right1){
if((nums1Length + nums2Length) % 2 == 0){
return (Math.max(left1, left2) + Math.min(right1, right2)) / 2.0;
}
else{
return Math.max(left1, left2);
}
}
else if(left1 > right2){ // Base Binary Search Condition
end = partition1 - 1;
}
else{
start = partition1 + 1; // Base Binary Search Condition
}

}

// Default Return Input
return 0.0;

}
}

Try solving now

2. Multiply Strings

Moderate
35m average time
55% success
0/80
Asked in companies
FacebookAmazonIBM

You are given two big numbers ‘A’ and ‘B’ as strings. Your task is to find the product of both the numbers.

Note:

There are no leading zeros in both the strings, except the number 0 itself.
Do not use any built-in Big Integer Library.
For Example:
If, A = 123, and B = 456.
So the product of both numbers will be 56088.
Problem approach

var multiply = function(num1, num2) {
return String(BigInt(num1) * BigInt(num2));
};

Try solving now
02
Round
Medium
Video Call
Duration60 minutes
Interview date8 Jul 2022
Coding problem2

This was the first technical round based on DSA taken by the SDE1 at amazon.

1. Program to validate IP address

Easy
15m average time
85% success
0/40
Asked in companies
OlaAmazonPhonePe

You are given the text ‘IPAddress’. Your task is to check if the given text ‘IPAddress’ is a valid ‘IPv4’ or not.

Conditions for a valid ‘IPv4’ are:

1. Text form of ‘IPAddress’ must be ‘a.b.c.d’
2. The values of a,b,c and d can vary from ‘0’ to ‘255’ and both ‘0’ and ‘255’ are inclusive.
Problem approach

lass Solution {
public List restoreIpAddresses(String s) {
List ans = new ArrayList<>();

int len = s.length();
for(int i = 1; i < 4 && i < len-2 ; i++ ){
for(int j = i + 1; j < i + 4 && j < len-1 ; j++ ){
for(int k = j+1 ; k < j + 4 && k < len ; k++){
String s1 = s.substring(0,i);
String s2 = s.substring(i,j); 
String s3 = s.substring(j,k); 
String s4 = s.substring(k,len); 
if(isValid(s1) && isValid(s2) && isValid(s3) && isValid(s4))
ans.add(s1+"."+s2+"."+s3+"."+s4); 
}
}
}
return ans;
}
boolean isValid(String s){
if(s.length() > 3 || s.length()==0 || (s.charAt(0)=='0' && s.length()>1) || Integer.parseInt(s) > 255)
return false;
return true;
}
}

Try solving now

2. Find unique combinations with sum B

Easy
15m average time
85% success
0/40
Asked in company
Amazon

Given a list of 'n' distinct positive integers and a non-negative integer 'B. Find the number of unique combinations possible from the elements of the list such that the sum of numbers in the combination is equal to 'B' . We can take an element from the list multiple times in our combination.

Elements in each combination must be in non-decreasing order.

For example:

Let the array ARR be [1, 2, 3] and B = 5. Then all possible valid combinations are-

(1, 1, 1, 1, 1)
(1, 1, 1, 2)
(1, 1, 3)
(1, 2, 2)
(2, 3)
Problem approach

class Solution {
List> result = new ArrayList<>();
public List> combinationSum2(int[] candidates, int target) {
Arrays.sort(candidates);//sort the array thereby the logic for handling dupes will work properly
dfs(candidates,target,0,new ArrayList<>());
return result;
}
public void dfs(int[] candid,int target,int start,List sub){
//Base conditions
if(target < 0){
return;
}
if(target == 0){
result.add(new ArrayList<>(sub));
}
for(int i=start;i if(i != start && candid[i] == candid[i-1]){
continue;
}//logic to skip duplicates
sub.add(candid[i]);// add the present element to sub temporary list
dfs(candid,target-candid[i],i+1,sub);//call dfs recursively 
sub.remove(sub.size()-1);//backtrack the step by removing the last added data in the list which caused the problem to end so we backtrack by removing it from the list 
}
}
}

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
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
2294 views
1 comments
0 upvotes
company logo
SDE - 1
3 rounds | 6 problems
Interviewed by Amazon
1593 views
0 comments
0 upvotes
company logo
SDE - 1
4 rounds | 8 problems
Interviewed by Amazon
8962 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
5983 views
5 comments
0 upvotes