Amazon logo

Amazon Hard Interview Questions

5 hard-level practice questions for Amazon technical interviews

Amazon software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.

Software Engineer Backend Engineer Frontend Engineer Full Stack Engineer Mobile Engineer Data Engineer Data Scientist ML Engineer DevOps Engineer DevOps Engineer Product Manager SRE Security Engineer Engineering Manager Data Analyst UX/UI Designer QA Engineer
coding Hard Verified Question #1

1. Binary Tree Cameras


Category: Binary tree coding problem
You are given the root of a binary tree. You need to install the minimum number of cameras on the tree nodes such that every node in the tree is...
Input: Binary tree
Output: Integer
Want to practise this one?
Create a free account to open the full question and practise Amazon questions with AI.
Sign up free
coding Hard Verified Question #2

2. [CodeSignal] Warehouse Emergency Deliveries


Category: Array coding problem
Amazon has opened a new warehouse recently. There are no products in the warehouse currently. The warehouse is under inspection for n days. The...
Input: Array
Output: Integer
coding Hard Verified Question #3

3. [CodeSignal] Permutation Sorter


Category: Combinatorics coding problem
Amazon engineers are testing a new tool, the Permutation Sorter, built to reorder sequences using limited operations. Given a permutation of...
Input: Integer(s)
Output: Integer
coding Hard Verified Question #4

4. [CodeSignal] Maximum Product Rating


Category: Array coding problem
The engineers at Amazon are working on a new rating system for their products. For each product, an array customer_rating is maintained for the...
Input: Array
Output: Computed result
coding Hard stack queue #1

1. [Monotonic Stack] — Maximize independently sortable batches


Background
Amazon fulfillment systems process large sequences of records that may need to be sorted before downstream processing. This problem models dividing such a sequence into contiguous batches that workers can sort independently, while preserving batch order when their results are concatenated.
Problem statement
Given an integer array arr, partition it into the maximum number of nonempty contiguous chunks such that sorting each chunk independently in ascending order and concatenating the sorted chunks in their original order produces exactly the same array as sorting arr globally.
Every element must belong to exactly one chunk. You may choose chunk boundaries, but you may not move elements between chunks or reorder the chunks. Values may be duplicated, and equal values are interchangeable. Return the maximum possible number of chunks, without modifying the input.
Function or class signature
  • max_chunks(arr: list[int]) -> int — Return the maximum number of valid independently sortable chunks.


Example 1:
Input: arr = [2, 1, 3, 4, 4]
Output: 4
Explanation: Choose [2, 1] | [3] | [4] | [4]. Sorting each chunk produces [1, 2] | [3] | [4] | [4], whose concatenation is globally sorted. Five chunks would leave 2 before 1, so four is optimal.
Example 2:
Input: arr = [5, 4, 3, 2, 1]
Output: 1
Explanation: Every possible boundary leaves a larger value on its left than a value on its right. Consequently, the entire array must be one chunk.
Constraints:
  • 1 <= len(arr) <= 100000.

  • Each element is an integer in [-1000000000, 1000000000].

  • Duplicate values are allowed.

  • The input must not be modified.

  • Target an O(n)-time solution, where n = len(arr).


Follow-up:
Turn this into an online data structure supporting append(value: int) -> int and undo_last_append() -> int, each returning the optimal chunk count for the current sequence. An empty sequence has zero chunks, and undo is called only on a nonempty sequence. How would you avoid recomputing from scratch, and what time and space bounds can you guarantee under alternating append and undo operations?
Want to practise this one?
Create a free account to open the full question and practise Amazon questions with AI.
Sign up free

Start practicing Amazon questions

Sign up for free to access walkthroughs, AI-generated questions, and more.

Get Started Free