← Amazon Interview Insights

Amazon·Software Engineer·Onsite - Coding / Algorithms·Junior

Junior
Jul 2026

Summary

Amazon new-grad SWE coding round with three problem areas: a from-scratch hash map, interval merging and intersection, and two water container variants. Pretty classic stuff but the breadth in one session was a lot to manage.

Questions Asked (5)

Q1

Implement a hash map from scratch supporting integer keys and values, with put, get, and remove operations, no built-in collections allowed. Also explain how you'd handle collisions and resize when the load factor gets too high.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

This took longer than I expected.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements and constraints, then outline the core design using an array of buckets with separate chaining for collision resolution. Walk through the implementation of put, get, and remove, explaining how resizing works when the load factor exceeds a threshold. Finally, discuss trade-offs and potential optimizations.

Pro tip: Mention that you would use a prime number for the bucket array size to reduce clustering, and that resizing should double the capacity and rehash all existing entries. Also, proactively discuss handling of null keys/values and thread-safety if relevant.

1. Clarify Requirements and Constraints

Ask about expected key/value types, load factor threshold, and whether thread-safety is needed. Confirm that no built-in collections (like arrays or lists) are allowed, but basic arrays are permitted.

2. Design the Data Structure

Propose an array of buckets, where each bucket is a linked list (or a custom dynamic array) of key-value pairs. Explain that collisions are handled via separate chaining.

3. Implement Core Operations

Describe put: compute hash, find bucket, traverse chain to update or append. Describe get: compute hash, traverse chain to find key. Describe remove: compute hash, traverse chain to find and remove node, adjusting links.

4. Handle Resizing

Track the number of entries and the load factor (entries / bucket count). When load factor exceeds a threshold (e.g., 0.75), create a new array of double the size (preferably a prime), rehash all existing entries, and replace the old array.

5. Discuss Trade-offs and Edge Cases

Talk about time complexity (average O(1), worst O(n)), choice of hash function, and potential improvements like using balanced trees for long chains. Mention handling of null keys/values and thread-safety if needed.

Key Points to Mention

  • Hash function design: use key's hashCode() and modulo a prime number to distribute keys uniformly.
  • Collision resolution: separate chaining with linked lists; mention that Java's HashMap uses this and converts to red-black trees for long chains.
  • Load factor and resizing: threshold (e.g., 0.75), doubling capacity, and rehashing all entries.
  • Time complexity: average O(1) for put/get/remove, worst-case O(n) if all keys collide.
  • Edge cases: null keys, null values, and handling of duplicate keys (update value).
  • Thread-safety: if needed, discuss synchronization or using ConcurrentHashMap-like techniques.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Given an unsorted list of closed intervals, merge all overlapping ones and return a sorted list of non-overlapping intervals.

Algorithms & Data Structures
Author's notes

Sort first by start time, then walk through and merge.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints (e.g., interval inclusivity, input size) and then propose sorting the intervals by start time. After sorting, iterate through the intervals and merge overlapping ones by comparing the current interval's start with the previous merged interval's end. This yields O(n log n) time due to sorting and O(n) space for the output.

Pro tip: Mention edge cases like empty input, single interval, and intervals that are adjacent but not overlapping (e.g., [1,2] and [2,3]) to show thoroughness. Also, discuss how you would handle large inputs that don't fit in memory, demonstrating scalability awareness.

1. Clarify the problem

Ask about interval inclusivity (closed intervals), input size, and whether the output should be sorted. Confirm that intervals are given as pairs of integers.

2. Sort intervals

Sort the intervals by their start times. This is crucial because it allows linear merging by ensuring that any overlapping intervals are adjacent.

3. Merge overlapping intervals

Initialize an empty result list. Iterate through sorted intervals; if the result is empty or the current interval's start is greater than the last merged interval's end, add it to the result. Otherwise, merge by updating the last interval's end to the maximum of both ends.

4. Return the result

After processing all intervals, return the result list, which contains non-overlapping intervals sorted by start time.

5. Analyze complexity and edge cases

State that time complexity is O(n log n) due to sorting, and space complexity is O(n) for the output. Discuss edge cases like empty input, single interval, and intervals that touch but don't overlap.

Key Points to Mention

  • Sorting by start time is key to achieving O(n log n) time complexity.
  • Merging condition: if current.start <= last.end, merge by updating last.end = max(last.end, current.end).
  • Handling edge cases: empty list, single interval, intervals with same start, and adjacent intervals.
  • Space complexity: O(n) for the output list, but can be O(1) extra space if merging in-place (though sorting may require extra space).
  • Alternative approaches: using a stack or sweep line, but sorting is simplest and efficient.
  • Scalability: for very large inputs, consider external sorting or streaming algorithms.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

Follow-up to the interval merge: given two separate lists of pairwise-disjoint sorted intervals, find all intersections between intervals across the two lists.

Algorithms & Data Structures
Author's notes

Two-pointer approach.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a two-pointer technique to traverse both sorted lists simultaneously, comparing the current intervals to find intersections. At each step, advance the pointer of the interval that ends first, as it cannot intersect with any subsequent interval in the other list. Collect all intersections and return them.

Pro tip: Clarify upfront whether the output should be sorted and whether intervals are closed or open, as this affects edge cases. Also, mention that the algorithm runs in O(m+n) time and O(1) extra space (excluding output), which is optimal for this problem.

1. Understand the problem and constraints

Confirm that each list is sorted and pairwise-disjoint, and that intervals are typically closed. Ask about output format and edge cases (e.g., touching endpoints).

2. Initialize pointers and result list

Set two pointers, one for each list, starting at index 0. Create an empty list to store the intersections.

3. Iterate while both pointers are in bounds

Compute the intersection of the current intervals: start = max(start1, start2), end = min(end1, end2). If start <= end, add [start, end] to the result.

4. Advance the pointer with the smaller end

Move the pointer of the interval that ends first, because it cannot overlap with any later interval in the other list. If ends are equal, advance both.

5. Return the result and analyze complexity

After the loop, return the list of intersections. State that time complexity is O(m+n) and space is O(1) extra (or O(k) for output).

Key Points to Mention

  • Two-pointer technique for sorted lists
  • Intersection condition: max(starts) <= min(ends)
  • Advancing the pointer with the smaller end
  • Time complexity O(m+n), space O(1) extra
  • Handling edge cases: touching intervals, empty lists, single interval
  • Output is naturally sorted if inputs are sorted

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q4

Given an array of heights representing vertical lines, find two lines that form a container with the maximum possible water area.

Algorithms & Data Structures
Author's notes

Two pointers from both ends, move the shorter side inward.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and edge cases, then propose a brute-force solution to establish baseline understanding. Optimize using a two-pointer technique that starts with the widest container and moves the pointer pointing to the shorter line inward, explaining why this is safe. Analyze time and space complexity, and discuss potential variations or optimizations.

Pro tip: At Amazon, interviewers value candidates who not only solve the problem but also articulate trade-offs and consider scalability. Explicitly state why the two-pointer approach is optimal and mention that it runs in O(n) time with O(1) space, which is crucial for large inputs.

1. Clarify and Restate

Ask clarifying questions about input constraints (e.g., array size, height values) and confirm the goal: maximize area = min(height[i], height[j]) * (j - i). Restate the problem in your own words to ensure alignment.

2. Brute Force Baseline

Describe a naive O(n^2) solution that checks all pairs of lines. This shows you can think of a straightforward approach and sets the stage for optimization.

3. Optimize with Two Pointers

Explain the two-pointer technique: initialize left at 0 and right at n-1, compute area, then move the pointer pointing to the shorter line inward. Justify why moving the shorter line cannot miss a larger area.

4. Analyze Complexity

State that the two-pointer approach runs in O(n) time and O(1) space, which is optimal. Compare with brute force to highlight efficiency gains.

5. Test and Edge Cases

Walk through a small example (e.g., [1,8,6,2,5,4,8,3,7]) to demonstrate correctness. Mention edge cases like empty array, two elements, or all equal heights.

Key Points to Mention

  • Area formula: min(height[i], height[j]) * (j - i)
  • Two-pointer initialization at extremes and moving the shorter line inward
  • Proof of correctness: moving the shorter line is safe because the width decreases and height is limited by the shorter line
  • Time complexity O(n) and space complexity O(1)
  • Edge cases: empty array, single element, two elements, all equal heights
  • Comparison with brute force O(n^2) to show optimization

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q5

Follow-up: given an elevation map as an array of heights, compute how much rainwater gets trapped in total.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Harder than it looks and I blanked for a second on the difference between this and the previous problem.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and walking through a small example to confirm understanding. Then present a two-pointer solution that computes trapped water in O(n) time and O(1) space, explaining the invariant that water above each bar is min(max_left, max_right) - height. Finally, discuss trade-offs with alternative approaches like dynamic programming or stack-based solutions.

Pro tip: Mention that you would validate the solution with edge cases like empty array, single bar, strictly increasing/decreasing heights, and flat terrain. This shows attention to detail and production-quality thinking, which Amazon values.

1. Clarify and Confirm

Restate the problem in your own words and ask clarifying questions about input constraints (e.g., array size, height range) and expected output. Walk through a small example to ensure alignment.

2. Brute Force Baseline

Briefly describe a naive O(n^2) approach: for each bar, compute max height to its left and right, then sum min(left_max, right_max) - height. This establishes a correct baseline and shows you can start simple.

3. Optimize with Two Pointers

Explain the O(n) time, O(1) space two-pointer technique: maintain left and right pointers, track max_left and max_right, and move the pointer with the smaller max inward, adding trapped water at each step.

4. Analyze Complexity and Trade-offs

State time and space complexity of the two-pointer solution and compare with alternatives like dynamic programming (O(n) space) or stack-based (O(n) space). Discuss when each might be preferable.

5. Test and Validate

Walk through edge cases (empty array, one element, increasing/decreasing, flat) and verify the algorithm produces correct results. Mention potential overflow or integer issues if heights are large.

Key Points to Mention

  • The amount of water trapped above each bar is determined by the minimum of the maximum heights to its left and right, minus its own height.
  • Two-pointer approach achieves O(n) time and O(1) space by processing from both ends and using the fact that water is bounded by the smaller of the two maxes.
  • Dynamic programming precomputes left and right max arrays in O(n) time and O(n) space, which is simpler but less space-efficient.
  • Stack-based approach processes bars and computes water when a higher bar is encountered, also O(n) time and O(n) space.
  • Edge cases: empty array returns 0, single bar returns 0, strictly increasing/decreasing returns 0, flat terrain returns 0.
  • Amazon leadership principles: customer obsession (clarify requirements), dive deep (analyze trade-offs), insist on highest standards (test edge cases).

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.