← Amazon Interview Insights

Amazon·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026

Summary

Amazon SWE coding round, pretty much one problem the whole time. Classic array question dressed up with a story about movies on a plane.

Questions Asked (1)

Q1

Given a flight duration (in minutes) and an array of movie lengths, find any two indices i and j where i != j such that the two movie durations add up exactly to the flight duration. Return an empty result if no such pair exists.

Algorithms & Data Structures
Author's notes

It's two sum.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use a hash map to store movie lengths and their indices while iterating through the array. For each movie, check if the complement (flight duration minus current movie length) exists in the map; if so, return the pair of indices. This yields O(n) time and O(n) space.

Pro tip: Clarify edge cases upfront, such as whether a movie can be paired with itself (i != j) and if the flight duration can be zero or negative. Also, mention that you'd handle duplicates by storing the first occurrence or using a set of seen complements.

1. Clarify requirements and edge cases

Confirm that i != j, that movie lengths are positive integers, and that the flight duration is an integer. Ask about handling multiple valid pairs and whether to return any pair or all pairs.

2. Choose the optimal data structure

Select a hash map (dictionary) to achieve O(n) time complexity by enabling constant-time lookups for complements.

3. Iterate and check complements

Traverse the array once. For each movie length, compute the complement and check if it exists in the hash map. If found, return the stored index and the current index.

4. Handle duplicates and self-pairing

Ensure that the same index is not used twice. If the complement equals the current movie length, verify that the stored index is different from the current index.

5. Return result and discuss complexity

If no pair is found, return an empty result. Analyze time and space complexity: O(n) time and O(n) space, which is optimal for this problem.

Key Points to Mention

  • Hash map for O(n) time complexity
  • Complement calculation: target = flight_duration - movie_length
  • Handling duplicates and ensuring i != j
  • Edge cases: no solution, empty array, negative durations
  • Space-time tradeoff compared to sorting + two-pointer approach
  • Returning indices, not values

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