Below is a list of 49 confirmed Amazon coding interview questions that were asked in software development engineer interviews just the past 10 months.
We identified these questions by analyzing a dataset of over 250 Glassdoor interview reports that were posted by real Amazon software development engineer candidates.
Practice up-to-date questions in the lists below to be prepared for the latest Amazon engineering interviews.
- 49 Amazon coding interview questions
- How to answer Amazon coding interview questions
- Amazon coding interview prep
49 Amazon coding interview questions
Arrays interview questions
- Given a sorted dictionary (array of words) of an alien language, find the order of characters in the language.
- Given an array arr[] of size n, its prefix sum array is another array prefixSum[] of the same size, such that the value of prefixSum[i] is arr[0] + arr[1] + arr[2] … arr[i].
- Given an array of integers, find the next biggest number.
- Given an array of distinct integers arr, find all pairs of elements with the minimum absolute difference of any two elements.
- Given an input of two arrays that represent computers' power output (powerOutputs) and boosted output (boostedOutputs) and a maximum allowed power (powerMax), return the maximum amount of adjacent computers that are less than or equal to powerMax given the formula totalPowerOutput = powerOutputs[i] + powerOutputs[i + 1...] + (boostedOutputs[i] + boostedOutputs[i + 1...] * numOfAdjacentComputers).
- Design a function that, given an array of lockers and an incoming package, the function will return the optimal locker for that package.
- Write a function that, given an array of entities and an integer N, keep looping around the array removing the Nth remaining entity until there is only one entity remaining. Return the remaining entity. Example Input: 2 elements, example loop below ...A E....B ..D.C Loop 1: Step 2 elements, flag B ...A E....[B] ..D.C Loop 2: Step 2 elements, flag D ...A E....x .[D]C Loop 3: Step 2 elements, Flag A ...[A] E....x ..x.C Loop 4: Step 2 elements, Flag E (NOT C, since B no longer exists ....x... [E]..x ..x.C.. Output: C
- Given a list of packages that need to be built and the dependencies for each package, determine a valid order in which to build the packages.
- Given char array ('w','h' combination), and int value w=work day, h=holiday, the int value represents the number of holidays that an employee can take off work. Find the longest possible holiday sub array.
- Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order.
- There are n gas stations along a circular route, where the amount of gas at the ith station is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from the ith station to its next (i + 1)th station. You begin the journey with an empty tank at one of the gas stations. Given two integer arrays gas and cost, return the starting gas station's index if you can travel around the circuit once in the clockwise direction, otherwise return -1.
- You are given an array prices where prices[i] is the price of a given stock on the ith day. You want to maximize your profit by choosing a single day to buy one stock and choosing a different day in the future to sell that stock. Return the maximum profit you can achieve from this transaction. If you cannot achieve any profit, return 0.
- You are given an integer array nums. The range of a subarray of nums is the difference between the largest and smallest element in the subarray. Return the sum of all subarray ranges of nums.
- Search an element in one sorted array which has infinite length.
- You are riding a bus, suppose in the East direction (bus direction will not change). Given the capacity of bus ‘c’ and an array such that [numberOfPassengers, PickUpLocation, DropLocation]. Check if you can drop all the passengers at their destinations. Return true or false eg: a. Bus capacity, c=4 [[3,1,5],[2,2,6]] -> Return false
- Place a set of integers into N arrays such that the sum of the medians of all the arrays is maximized.
For more help with arrays, take a look at our full guide on the subject, which includes 50+ array interview questions.
Linked list interview questions
- Remove the duplicate node(s) from a linked list.
- Reverse a linked list.
- In a linked list, find the second highest number of each node
- Given a user id and a list of purchases where each item in the list has a product id and user id #, return a list of products that the user hasn't # yet purchased yet but have been purchased by other users that have already purchased at least one thing in common with that user.
- Given an integer array marks, which comprises marks scored by a student (out of 100) in different subjects, assign a grade to the student. The grade is found out by taking the percentage of the marks scored by the student.
- Given a list of words (without duplicates), please write a program that returns all concatenated words in the given list of words. A concatenated word is defined as a string that is comprised entirely of at least two shorter words in the given array.
- Find the sum of all numbers in a linked list.
- You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself.
- Given the number of pages in each chapter of a book (in the form of a linked list) you read a chapter from the front and a chapter from the back each day (guaranteed an even number of chapters). What day did you read the most number of pages?
For more help with linked lists, take a look at our full guide on the subject, which includes 40+ linked list interview questions.
Strings interview questions
- Given string s, return the longest palindromic substring in s.
- Given a vector of strings, group the strings which are anagrams eg:- {ada,mnj,kkl,mjn,aad} Ans:- {{ada,aad},{mnj,mjn},{kkl}}
- Reverse a string and stack it.
- Given a string s which represents an expression, evaluate this expression and return its value.
- Given two strings, determine if they are equal after backspace operators are processed.
- Find the number of unique letters in all substrings of a string.
- Given a string s, find the length of the longest substring without repeating characters.
- Given a string s, return the maximum number of ocurrences of any substring under the following rules: The number of unique characters in the substring must be less than or equal to maxLetters, and the substring size must be between minSize and maxSize inclusive.
- Given a string of heads or tails (e.g. "HHHTH"), return the minimum number of flips so that all heads are before all tails.
For more help with strings, take a look at our full guide on the subject, which includes 51 string interview questions.
BFS/DFS interview questions
- Given a 2D grid of M row by N columns, where each cell can either be "land" or "water,” find the total number of islands.
- Given a dictionary, and two words ‘start’ and ‘target’ (both of same length). Find length of the smallest chain from ‘start’ to ‘target’ if it exists, such that adjacent words in the chain only differ by one character and each word in the chain is a valid word i.e., it exists in the dictionary. It may be assumed that the ‘target’ word exists in dictionary and length of all dictionary words is same.
- Given a matrix of N by M elements. These elements will be one of the following: E for an entrance or an exit, _for a traversable path, or X for an untraversable path. Design an algorithm that can traverse this matrix and determine the shortest path between the two E nodes. Assume that there will always be exactly one entrance and one exit (again, both are represented by an E). Assume that there will always be a solution path, though there may be multiple. You may not move diagonally.
- Given a 2D screen, location of a pixel in the screen and a color, replace color of the given pixel and all adjacent same colored pixels with the given color. (i.e. The flood fill function in Paint.)
- Given a dictionary, and two words ‘start’ and ‘target’ (both of same length). Find length of the smallest chain from ‘start’ to ‘target’ if it exists, such that adjacent words in the chain only differ by one character and each word in the chain is a valid word i.e., it exists in the dictionary. It may be assumed that the ‘target’ word exists in dictionary and length of all dictionary words is same.
For more help with DFS and BFS, take a look at our full guides, which include 50+ depth-first search interview questions and 44 breadth-first search interview questions.
Trees interview questions
- Reverse a binary tree.
- Given two trees, determine if they are mirrors of one another.
- You are given the root of a binary tree with n nodes where each node in the tree has node.val coins. There are n coins in total throughout the whole tree. In one move, we may choose two adjacent nodes and move one coin from one node to another. A move may be from parent to child, or from child to parent. Return the minimum number of moves required to make every node have exactly one coin.
- Print a binary tree in zig-zag order.
- A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once. Note that the path does not need to pass through the root. The path sum of a path is the sum of the node's values in the path. Given the root of a binary tree, return the maximum path sum of any non-empty path.
For more help with trees, use our full guide on the subject, with 50+ tree interview questions and solutions.
Other interview questions (Big O, dynamic programming, graphs, sorting)
- What are the time and space complexities of the solution you’ve found?
- Improve the time complexity of a given code.
- Write a code to print a sequence of numbers starting with N, where A[0] = N, without using a loop, in which A[i+1] = A[i] - 5, until A[i] > 0. After that A[i+1] = A[i] + 5. Repeat it until A[i] = N
- Given a set of cities and the distance between every pair of cities, find the shortest possible route that visits every city exactly once and returns to the starting point.
- Merge two streams of sorted integers.
For help on all of these subjects, use our guides to Big O notation and complexity analysis, dynamic programming, graphs, and sorting.
How to answer Amazon coding interview questions
To learn how to answer coding interview questions, you must first be able to approach them systematically. You might solve a coding question in different ways, but at the end of the day, you need an approach that will consistently:
- Show your interviewer that you have the knowledge they need
- Break the problem down into manageable steps
With that in mind, one of our favorite approaches is summarized in the following video from Amazon:
The approach shown in the video above can be boiled down into 4 main steps:
- Clarify
- Plan
- Implement
- Test & optimize
Next, we’ll dig into each of these steps in more detail, with a minute-by-minute interview flow, provided to us by Suman B. Let's get started!
1. Clarify (minutes 0-10)
Don’t jump straight into the question without consulting your interviewer. Instead, start by asking questions to remove any ambiguity and to explore the edges of the problem.
This is a good time to set up a dialogue with your interviewer. They are not just looking for a candidate who can solve a problem, but one who can work effectively in a team of other engineers.
Let’s jump into how this will look during the interview.
Minutes 0-3: Understand the question
If the question has been written down for you, take the time to read it thoroughly at least twice, to be sure that you’ve picked up on all the details. Repeat the question back to the interviewer in your own words, so that they can flag anything that you may have initially misunderstood.
Minutes 3-8: Ask clarifying questions
Once you’re sure that you understand the basic question, clarify the unwritten details. For example, ask for constraints (e.g. 0<= N < 1000), consider edge cases, identify corner cases, specify what language you’ll be coding in, etc.
Minutes 8-10: Specify assumptions
Finally, before starting work on the solution, consider any assumptions you’re making (e.g. input format, range, sorted or unsorted list, etc). Specify those to the interviewer, so that they can tell you if that is a correct assumption to make, given the problem.
2. Plan (minutes 10-20)
Now that you have a complete understanding of the coding question, it’s time to start making your plan. Here is where you can discuss potential approaches with the interviewer, pick the one that is the most appropriate, and lay out the high level steps to get there.
Let’s take a look at how this will play out in the interview:
Minutes 10-15: Find a solution
Take five minutes to think through a solution to the problem. It does not need to be optimal at this stage. Map out your solution on the whiteboard or its virtual equivalent, making sure that what you add is comprehensible to both you and the interviewer. The goal is to find any solution (at least brute-force) and then find improvements. Keep walking through your steps out loud so that the interviewer can guide you.
Minutes 15-20: Explain your solution
Before you implement your plan, make sure that you’ve brought your interviewer up to speed. If you’ve identified multiple approaches to the problem, go over each and explain why you’ve chosen the one you decide to move forward with. Ensure that the interviewer is aligned with your solution before you start coding, in order to save time down the road and to allow the interviewer to capture the right data points during your coding.
3. Implement (minutes 20-35)
Now it’s time for the main event. Write legible, clean code rather than pseudocode, and comment out loud on what you’re doing. Alternatively, if you have a hard time talking and writing, you can spend a few minutes coding quietly, then stop periodically to explain what you’ve done.
Here’s how much time you should spend on these steps:
Minutes 20-25: Optimize the solution
Once you’ve talked through your solution with the interviewer, optimize it. Consider any points you may have missed when you first thought of the solution, and what you can do to make it better. Explain your reasoning thoroughly and keep an eye out for the cues of the interviewer, which will let you know whether or not you’re on the right track. You can prompt them by asking, “how does that sound?” before moving on to coding.
Minutes 25-35: Write the code
Now, write that code! Explain what you’re doing, and make an effort to write clearly—don’t use shorthand variables. Include descriptive variable names, structure the code well, consider boundary conditions or empty inputs, etc. Make your code modular and eliminate duplicate code. If you realize you’ve forgotten an important function, simply go back and insert it, while clarifying what you’re doing out loud.
4. Test and optimize (minutes 35-50)
Once you have your code on the board, you’ve got to take the time to run through and test it, then optimize it given what you’ve found in testing. Start by testing with a simple example, then try breaking your code with edge and corner cases.
Don’t forget to calculate the time and space complexity of your code, and discuss how you can possibly improve it. If you find any better solutions while testing and evaluating your code’s complexity, ask the interviewer if they’d like you to implement it.
Here’s how that will play out:
Minutes 35-40: Test run your code
When testing your code, run it through multiple cases, starting with the basic use case, moving into a more complex case, and finally test for failure and edge cases. Consider anything that might break your code, and what you can do to address it [e.g. test cases like asserrEquals(findMax(10,20), 20)].
Minutes 40-50: Optimize your code
Finally, work out the time and space complexity of your code. Explain it in simple terms to your interviewer, and use it as a jumping off point to consider ways you can optimize your code. If time permits, write out the optimal code and discuss it.
Minutes 50-60: Q & A
These last few minutes of the interview are a good time to ask any questions you might have about the company and what your experience would be like working there. The interviewer may have additional questions for you as well. If the interviewer has clearly moved on from the coding problem, consider it finished and do not try to rehash any of its finer points.
Now that you’ve seen a breakdown of a coding interview flow, let’s take a look at a full example answer.
Amazon coding interview prep
Now that you know what questions to expect and how to answer them in Amazon coding interviews, here are 3 steps you should take to make sure you’re fully prepared.
Learn about Amazon’s culture
Most candidates fail to do this. But before investing tons of time preparing for an interview at Amazon, you should take some time to make sure it's actually the right company for you.
Amazon is prestigious and it's tempting to assume that you should apply, without considering things more carefully. But, it's important to remember that the prestige of a job (by itself) won't make you happy in your day-to-day work. It's the type of work and the people you work with that will.
If you know engineers who work at Amazon or used to work there, talk to them to understand what the culture is like. We would also recommend reading the following resources:
- Amazon’s 16 leadership principles (by Amazon)
- Amazon's technology culture video mix (by Amazon)
- Amazon vision and mission analysis (by Panmore Institute)
- Amazon strategy teardown (by CB Insights)
Get familiar with the interview process
Of course, coding rounds will not be the only interviews that you’ll have to face for a technical role at Amazon. While coding interviews are going to be a key part of impressing interviewers and ultimately getting an offer, there will be other types of questions that you’ll need to crack.
At Amazon, for example, there is a heavy emphasis on the company’s 16 leadership principles, which every interviewer will be testing you on. To learn more about this, plus the exact interview process for your role, refer to one of our complete Amazon interview guides below.
- Amazon software development engineer interview
- Amazon software development manager interview
- Amazon data engineer interview
- Amazon machine learning engineer interview
Do mock interviews
Finally, you should also try to practice coding mock interviews with expert ex-interviewers, as they’ll be able to give you much more accurate feedback than friends and peers.
If you know technical candidates who can help you with your interviews, that can be a good place to start. Have them interview you and give feedback after each session.
However, it can be tough to find the right connections to make that happen. And it might also be difficult to practice multiple hours with that person unless you know them really well.
Here's the good news. We've already made the connections for you. We’ve created a coaching service where you can practice 1-on-1 with ex-interviewers from leading tech companies like Amazon. Learn more and start scheduling sessions today.