← Amazon Interview Insights

Amazon·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

Amazon SWE technical phone screen focused on implementing a nested object path accessor, basically a mini version of lodash get. The question sounds deceptively simple but has a lot of edge cases hiding in it.

Questions Asked (1)

Q1

Implement a get(object, path) function that traverses a nested structure of maps and arrays using a path string like 'ab[1].c.d[2][13]', returning the value at that path or a sentinel if any segment is missing.

Algorithms & Data StructuresTechnical Trade-offsAPI & Integrations
Author's notes

The tricky part isn't the happy path, it's all the stuff you have to ask before writing a single line.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements: the path syntax, the sentinel value, and edge cases like empty paths or invalid characters. Then, design a parser that tokenizes the path into keys and indices, and a traversal function that iterates through the tokens, checking at each step if the current value is a map or array and if the key/index exists. Finally, discuss trade-offs between iterative and recursive approaches, and consider performance and error handling.

Pro tip: Mention that you would use a sentinel object (e.g., a unique symbol or a constant) to distinguish between a missing path and a legitimate undefined/null value, and discuss how this design choice affects API usability and error handling.

1. Clarify requirements and edge cases

Ask about the path syntax, expected data types, sentinel value, and how to handle invalid paths or missing segments. Confirm whether the function should throw errors or return the sentinel.

2. Design the path parser

Outline a tokenizer that splits the path into segments: property names (e.g., 'ab') and array indices (e.g., '[1]'). Consider using regular expressions or a state machine to handle nested brackets and dots.

3. Implement the traversal logic

Describe an iterative loop over tokens: for each token, check if the current value is an object/array and if the token exists. If not, return the sentinel. Update the current value accordingly.

4. Handle edge cases and optimize

Discuss handling empty paths, leading/trailing dots, consecutive brackets, and non-existent keys. Consider performance optimizations like early termination and avoiding unnecessary parsing.

5. Test and validate

Walk through test cases: valid paths, missing segments, invalid syntax, and edge cases like empty objects/arrays. Explain how you would verify correctness and handle errors.

Key Points to Mention

  • Path parsing: tokenizing property names and array indices, handling nested brackets and dots.
  • Traversal algorithm: iterative vs recursive, checking types (map vs array) at each step.
  • Sentinel value: using a unique object to distinguish missing paths from undefined/null values.
  • Error handling: returning sentinel vs throwing exceptions, and how to handle invalid paths.
  • Edge cases: empty path, non-existent keys, out-of-bounds indices, and non-object intermediate values.
  • Performance: time complexity O(n) where n is path length, space complexity O(1) for iterative approach.

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