# Common Interview Questions for Amazon - IQCode

### Amazon Interview Questions

There have been a total of 203 interview questions found for Amazon.

The questions cover a range of topics, including technical skills, problem-solving abilities, past experiences, and behavioral traits. It is important for candidates to be well-prepared and knowledgeable about Amazon’s culture and values to increase their chances of success in the interview process.

`Remember to always present yourself in a professional and confident manner during any communication with Amazon representatives.`

### ABOUT AMAZON

Amazon, the earth's most customer-centric company, was founded by Jeff Bezos in Bellevue, Washington on July 5th, 1994. It is an American multinational technology company that focuses on various fields including e-commerce, cloud computing, artificial intelligence, and digital streaming. Amazon is also recognized as one of the Big Five companies in the United States information technology industry alongside Google, Apple, Microsoft, and Facebook.

Amazon is renowned for its massive disruption of industries through technological innovation and a vast scale. With the world's most significant online marketplace, an AI assistant provider, and a cloud computing platform, Amazon presently employs over 600,000 individuals, with over 50,000 located in India alone. It's presently the largest internet company globally by revenue and the second-largest non-government employer in the United States, with the highest global brand valuation.

With the variety of services and opportunities Amazon provides, it's obvious why so many individuals seek to join Amazon and be part of its evergreen culture. But, what is the secret sauce to Amazon's enormous success? If you posed this question to any of Amazon's employees, we're confident they would all say the same thing: The Amazon Leadership Principles.

[Amazon HQ]

### Amazon Interview and Coding Process: Tips and FAQ

This article provides insights into the interview process at Amazon, including coding questions that may be asked during the process. We also offer tips to help you prepare for an Amazon interview to give you the best chance of success. Below are some frequently asked questions about Amazon interviews.

```
# Sample code to demonstrate the Amazon coding question format
# This code prints numbers from 1 to 100. For multiples of 3, it prints "Amazon" instead of the number,
# for multiples of 5, it prints "Web" instead of the number and
# for numbers that are multiples of both 3 and 5, it prints "Amazon Web"
```

for i in range(1, 101): if i % 3 == 0 and i % 5 == 0: print("Amazon Web") elif i % 3 == 0: print("Amazon") elif i % 5 == 0: print("Web") else: print(i)

**Tips for Interviewing at Amazon:**

- Research Amazon’s leadership principles and make sure you can discuss how they relate to your work experience and personal values.

- Practice coding questions related to the position you are interviewing for.

- Be prepared to answer behavioral questions that focus on your past experiences and how you would handle hypothetical situations.

- Dress professionally and be on time for your interview.

- Make sure to ask thoughtful questions about the role and the company culture during your interview.

**FAQ for Amazon:**

**Q:** How long does the Amazon interview process take?

**A:** The Amazon interview process can take anywhere from a few weeks to a few months. It typically includes multiple rounds of interviews, including technical and behavioral assessments.

**Q:** What benefits does Amazon offer to its employees?

**A:** Amazon offers a variety of benefits to its employees, including health insurance, retirement savings plans, stock options, and generous parental leave policies.

**Q:** Does Amazon offer remote work options?

**A:** Yes, Amazon does offer remote work options for some positions. However, the availability of remote work varies by position and location.

Amazon Interview Process

-------------------------

Recruiting Process

To get noticed by Amazon recruiters, it is best to maintain a good LinkedIn profile and message recruiters. It is also advised to get a referral from an Amazon employee in addition to applying through the Amazon job portal.

Interview Rounds

Amazon conducts an initial coding test, followed by four interview rounds. The coding test comprises DS/Algo problems. The first round is a Human Resources (HR) round where the candidate is asked behavioral and computer science theory questions. The next three rounds are solely focused on DS/Algo problems.

Post-Interview

After the rounds, the recruiter contacts the candidate with the verdict. Technical skills and leadership principles are both considered in the evaluation of the candidate.

Hired!

Once the team and candidate are both comfortable and ready to start, the recruiter sends an offer letter, and the candidate is officially HIRED!

Interview Rounds

HR Round (Round 1): The candidate is asked computer science theory and behavioral questions. These questions may include the candidate's experience with previous companies and conflicts they may have faced with colleagues or managers.

Data Structures and Algorithms Rounds (3 Rounds): The candidate is tested on DS/Algo problems, and production-ready code may be expected. The problems have varying difficulty levels but are not the sole determining factor for the final offer. Leadership principles also come into play. The interviews are conducted on Amazon Chime.Amazon Coding Questions

Gas Station

Problem: Given two integer arrays A and B of size N. There are N gas stations along a circular route where the amount of gas at station i is A[i]. You have a car with an unlimited gas tank and it costs B[i] of gas to travel from station i to its next station (i+1). You begin the journey with an empty tank at one of the gas stations. Return the minimum starting gas station's index if you can travel around the circuit once, otherwise, return -1.

Solution: We can solve this problem using a greedy approach where we maintain a running sum of all fuel available from gas stations and required fuel for the journey. We start from the first gas station and check if we have enough fuel to reach the next. If yes, we continue, if not, we reset and start from the next station. If we complete the journey successfully, we return the starting gas station index.

Code:

```
def can_complete_circuit(gas, cost):
n = len(gas)
total_tank, curr_tank = 0, 0
starting_station = 0
for i in range(n):
total_tank += gas[i] - cost[i]
curr_tank += gas[i] - cost[i]
if curr_tank < 0: # If we cannot reach next station
starting_station = i + 1 # Begin from next station
curr_tank = 0 # Reset tank
return starting_station if total_tank >= 0 else -1
```

Majority Element

Problem: Given an array of size n, find the majority element. The majority element is the element that appears more than floor(n/2) times.

Solution: We can solve this problem by using a hashmap to store the frequency of each element in the array and then finding the element with the highest frequency.

Code:

```
def majority_element(nums):
n = len(nums)
freq = {}
for i in range(n):
if nums[i] in freq:
freq[nums[i]] += 1
else:
freq[nums[i]] = 1
if freq[nums[i]] > n//2:
return nums[i]
```

Distribute Candy

Problem: There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements: Each child must have at least one candy. Children with a higher rating get more candies than their neighbors. What is the minimum candies you must give?

Solution: We can solve this problem by maintaining two arrays of size n, one for the number of candies given to the left neighbor and one for the right neighbor. We start by assigning one candy to each child. Then, we traverse the array from left to right and give additional candies to a child if its rating is greater than its left neighbor. Similarly, we traverse the array from right to left and give additional candies to a child if its rating is greater than its right neighbor. Finally, we take the maximum of corresponding elements in both arrays and return their sum.

Code:

```
def candy(ratings):
n = len(ratings)
left_to_right = [1] * n
right_to_left = [1] * n
for i in range(1, n):
if ratings[i] > ratings[i-1]:
left_to_right[i] = left_to_right[i-1] + 1
for i in range(n-2, -1, -1):
if ratings[i] > ratings[i+1]:
right_to_left[i] = right_to_left[i+1] + 1
result = 0
for i in range(n):
result += max(left_to_right[i], right_to_left[i])
return result
```

Longest Increasing Subsequence

Problem: Find the longest increasing subsequence of a given array of integers, A. In other words, find a subsequence of array in which the subsequence’s elements are in strictly increasing order, and in which the subsequence is as long as possible.

Solution: We can solve this problem by using dynamic programming. We maintain an array of the longest increasing subsequence ending at each element of the input array. We initialize the array with 1 as minimum possible length. Then, for each index, we traverse the previous elements and update the value of the current index if its previous element is smaller than the current element.

Code:

```
def longest_increasing_subsequence(A):
n = len(A)
if n == 0: return 0
dp = [1] * n
for i in range(1, n):
for j in range(0, i):
if A[i] > A[j]:
dp[i] = max(dp[i], dp[j] + 1)
return max(dp)
```

Max Product Subarray

Problem: Find the contiguous subarray within an array (containing at least one number) which has the largest product. Return an integer corresponding to the maximum product possible.

Solution: We can solve this problem using dynamic programming where we maintain the contiguous subarray with maximum and minimum product ending at each index. We can either start or stop a subarray at each index, thus, we will keep two arrays for the maximum and minimum subarrays ending at each index. The product of a subarray ending at current index can be the product of a previous subarray times the current element or solely the current element.

Code:

```
def maxProduct(A):
n = len(A)
if n == 0: return 0
max_dp = [0] * n
min_dp = [0] * n
max_dp[0] = min_dp[0] = max_so_far = A[0]
for i in range(1, n):
if A[i] >= 0:
max_dp[i] = max(max_dp[i-1] * A[i], A[i])
min_dp[i] = min(min_dp[i-1] * A[i], A[i])
else:
max_dp[i] = max(min_dp[i-1] * A[i], A[i])
min_dp[i] = min(max_dp[i-1] * A[i], A[i])
max_so_far = max(max_so_far, max_dp[i])
return max_so_far
```

Ways to Decode

Problem: A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' -> 1 'B' -> 2 ... 'Z' -> 26 . Given an encoded message A containing digits, determine the total number of ways to decode it modulo 10^9 + 7.

Solution: We can solve this problem using dynamic programming where we maintain an array of the number of possible ways to decode the message till the current index. We start by initializing the first two indexes of the array with 1 as there can be only one way to decode a single digit number and if the second digit is a zero, then there is only one way to decode it as we cannot have a 0th code. Then, we traverse through the message and check if we can combine the current digit with its previous digit to form a valid two-digit code.

Code:

```
def numDecodings(A):
n = len(A)
if n == 0: return 0
dp = [0] * (n+1)
dp[0] = 1
dp[1] = 1 if A[0] != '0' else 0
for i in range(2, n+1):
if int(A[i-1:i]) > 0:
dp[i] += dp[i-1]
if 10 <= int(A[i-2:i]) <= 26:
dp[i] += dp[i-2]
dp[i] %= 10**9 + 7
return dp[n]
```

Best Time to Buy and Sell Stocks II

Problem: Say you have an array, A, for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete as many transactions as you like.

Solution: We can solve this problem using a greedy approach where we add the profit whenever we see an ascending trend or a peak. As we can complete as many transactions as we like, we can also add the profit whenever we see a descending trend or a valley.

Code:

```
def maxProfit(A):
n = len(A)
if n == 0: return 0
profit = 0
for i in range(1, n):
if A[i] > A[i-1]:
profit += A[i] - A[i-1]
return profit
```

Best Time to Buy and Sell Stocks III

Problem: Say you have an array, A, for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum profit. You may complete at most two transactions.

Solution: We can solve this problem using dynamic programming where we maintain two arrays as in Best Time to Buy and Sell Stocks II problem but for each index, we calculate the maximum possible profit up to that index using one of the two transactions. We then calculate the maximum possible profit we can earn using two transactions by adding the maximum profit till previous index using one transaction plus maximum profit till current index using second transaction.

Code:

```
def maxProfit(A):
n = len(A)
if n == 0: return 0
dp1 = [0] * n
dp2 = [0] * n
min_so_far = dp1[0] = A[0]
for i in range(1, n):
min_so_far = min(min_so_far, A[i])
dp1[i] = max(dp1[i-1], A[i] - min_so_far)
max_so_far = dp2[n-1] = A[n-1]
for i in range(n-2, -1, -1):
max_so_far = max(max_so_far, A[i])
dp2[i] = max(dp2[i+1], max_so_far - A[i])
result = 0
for i in range(n):
result = max(result, dp1[i] + dp2[i])
return result
```

Best Time to Buy and Sell Stocks I

Problem: Say you have an array, A, for which the ith element is the price of a given stock on day i. If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock), design an algorithm to find the maximum profit.

Solution: We can solve this problem using a greedy approach where we maintain the minimum stock price seen so far and the maximum profit we can earn on selling the stock at each day. We compare the profit earned on each day with the maximum profit seen so far.

Code:

```
def maxProfit(A):
n = len(A)
if n == 0: return 0
max_profit = 0
min_price = A[0]
for i in range(1, n):
max_profit = max(max_profit, A[i] - min_price)
min_price = min(min_price, A[i])
return max_profit
```

Max Sum Path in Binary Tree

Problem: Given a binary tree T, find the maximum path sum. The path may start and end at any node in the tree.

Solution: We can solve this problem using recursion where we calculate the maximum path sum for left and right subtrees and include the current node in the path. We calculate the sum using the Max Path through Root node by adding node values from both the left and right branch by subtracting the interlink. Then we compare these values and return whichever is maximum - either maximum left branch path sum, maximum right branch path sum or the maximum path through root.

Code:

```
def maxPathSum(A):
res = [float('-inf')]
maxPath(A, res)
return res[0]
def maxPath(node, res):
if not node: return 0
l_sum = maxPath(node.left, res)
r_sum = maxPath(node.right, res)
max_straight = max(max(l_sum, r_sum) + node.val, node.val)
max_case_val = max(max_straight, l_sum + r_sum + node.val)
res[0] = max(res[0], max_case_val)
return max_straight
```

Palindrome Partitioning II

Problem: Given a string A, partition A such that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning of A.

Solution: We can solve this problem using dynamic programming where we keep track of the minimum cuts needed to make all substrings till the current index of the string a palindrome. We start with a cost matrix of zeros and maintain a palindrome boolean matrix for all possible substrings. Then, we traverse the input string and for each index, we update the palindrome matrix for all possible substrings using a two pointer approach. We update the cost matrix using the minimum cost of the previous palindrome substring plus 1.

Code:

``` def minCut(A): n = len(A) if n == 0: return 0 is_palindrome = [[False] * n for _ in range(n)] cost = [0] * (n+1) for i in range(n): is_palindrome[i][i] = True cost[i+1] = i + 1 for l in range(2, n+1): for i in range(n-l+1): j = i + l - 1 if l == 2: is_palindrome[i][j] = (A[i] == A[j]) else: is_palindrome

### Tips for Amazon Interview Preparation

Amazon is a highly sought-after employer due to its rich heritage, work culture, and Leadership Principles. To help you crack Amazon's interview and secure a job, here are some tips:

* Diligently understand Amazon's Leadership Principles. Amazonians pride themselves on their commitment to these principles, and referencing specific instances where you have applied them in your life will leave a positive impression on interviewers. This demonstrates your genuine interest in the company.

* Have a solid understanding of data structures and algorithms. Amazon favors candidates who excel at problem-solving. To make a good impression, prove that you have honed your logic structures and problem-solving skills through one or two standout projects.

* Use the STAR method when responding to behavioral interview questions. STAR stands for Situation, Task, Action, and Result. When answering a question using this method, describe the situation, the task you needed to complete, the action you took to respond, and the resulting outcome. Think carefully about all the involved details and let the interviewer know how much of an impact the experience had on your life, as well as the lives of those who were involved.

* Understand and describe your strengths. During the interview, be confident about highlighting your strengths. If you don't show the interviewer how good you are at the skills you possess, it could affect your prospects of being hired.

* Engage in conversation with your interviewer to keep the discussion flowing. A successful interview isn't just about having the best solution to a given problem. It's also about making sure the interviewer fully understands your thought process. Make them feel like they are part of the interview process, and don't hesitate to ask questions when prompted.Frequently Asked Questions (FAQ) about Amazon Interviews

------------------------------------------

### What are the different rounds of Amazon interviews?

Amazon conducts five rounds of interviews; four focusing on Data Structures and Algorithms, one on System Design, and one on HR.

### Are Amazon interviews difficult?

The difficulty level of Amazon interviews varies based on how well-prepared the candidate is. The questions usually fall between easy to medium level for standard interviews, but each person's experience can differ.

### How do I apply for a job at Amazon?

Go to the Amazon Jobs portal and submit your application for any open positions that match your skill set.

### Can I apply for multiple job roles at Amazon?

Yes, candidates can apply for several different roles as long as they align with their interests and skills. They will be evaluated based on each position's requirements, and multiple interviews can be done simultaneously.

### What are some good questions to ask an Amazon interviewer?

Ask the interviewer about the company culture, the technologies Amazon currently uses to develop their products, and future innovations slated for release. You can also inquire about their personal experience at Amazon and any skills you need to develop further.

### What is the best way to prepare for coding interviews at Amazon?

Practice is key to success in coding interviews at Amazon. Make a concerted effort to solve complex Data Structures and Algorithms problems. Familiarize yourself with fundamental computer science concepts such as Object-Oriented Programming, Computer Networks, and Operating Systems.

### Does Amazon have a dress code?

No, Amazon does not have a dress code; however, employees are expected to dress decently at work.

### Are specific projects like Web or Android Development or Machine Learning a requirement for getting hired at Amazon?

No, Amazon only requires good problem-solving skills to get hired for SDE positions. However, having a few well-developed projects on your resume can give you an advantage in the hiring process as it demonstrates expertise in your field of interest.

### Technical Interview Guides

Here are guides for technical interviews, categorized from introductory to advanced levels.

View All### Best MCQ

As part of their written examination, numerous tech companies necessitate candidates to complete multiple-choice questions (MCQs) assessing their technical aptitude.

View MCQ's