Skip to content

Amazon Technical Questions

Practice with Amazon technical questions covering DSA problems, system design concepts, and coding fundamentals. These questions are representative of what you’ll encounter in Amazon’s online assessment and technical interviews.

What’s Included:

  • Coding Problems: Arrays & Strings, Graphs & Trees, Bit Manipulation & DP
  • System Design Questions: OOP and scalable system design problems
  • Detailed Solutions: Step-by-step code explanations in Java/C++
  • Practice Tips: Strategies for solving Amazon interview questions effectively

Sample Amazon questions with solutions

Coding/⟦ph307⟧

Two Sum Variant Problem: 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.

Example: nums = [2, 7, 11, 15], target = 9. Output: [0, 1]

Code: (Java/C++)

class Solution {
public int[] twoSum(int[] nums, int target) {
Map<Integer, Integer> map = new HashMap<>();
for (int i = 0; i < nums.length; i++) {
int complement = target - nums[i];
if (map.containsKey(complement)) {
return new int[]{map.get(complement), i};
}
map.put(nums[i], i);
}
return new int[]{};
}
}

Sliding Window Maximum Problem: You are given an array of integers nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position.

Example: nums = [1,3,-1,-3,5,3,6,7], k = 3. Output: [3,3,5,5,6,7]

Code: (Java/C++)

class Solution {
public int[] maxSlidingWindow(int[] nums, int k) {
int n = nums.length;
if (n == 0 || k == 0) return new int[0];
int[] result = new int[n - k + 1];
Deque<Integer> deque = new ArrayDeque<>();
for (int i = 0; i < n; i++) {
// Remove indices that are out of the current window
if (!deque.isEmpty() && deque.peekFirst() == i - k) {
deque.pollFirst();
}
// Remove indices whose corresponding values are less than nums[i]
// because they will not be the maximum in the current window
while (!deque.isEmpty() && nums[deque.peekLast()] < nums[i]) {
deque.pollLast();
}
deque.offerLast(i);
// The first element in the deque is the maximum for the current window
if (i >= k - 1) {
result[i - k + 1] = nums[deque.peekFirst()];
}
}
return result;
}
}

String Compression Problem: Given an array of characters chars, compress it using the following algorithm:

If the character count is 1, append the character. If the character count is greater than 1, append the character followed by the count.

Example: chars = [“a”,“a”,“b”,“b”,“c”,“c”,“c”]. Output: [“a”,“2”,“b”,“2”,“c”,“3”]

Code: (Java/C++)

class Solution {
public int compress(char[] chars) {
int writeIndex = 0;
int count = 1;
for (int i = 1; i <= chars.length; i++) {
if (i < chars.length && chars[i] == chars[i - 1]) {
count++;
} else {
chars[writeIndex++] = chars[i - 1];
if (count > 1) {
String countStr = String.valueOf(count);
for (char c : countStr.toCharArray()) {
chars[writeIndex++] = c;
}
}
count = 1;
}
}
return writeIndex;
}
}
Practice More Amazon Interview Questions →

Comments & Suggestions

Similar companies

Google · Microsoft · Meta · Apple · Netflix · Flipkart