← Amazon Interview Insights

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

IntermediatePrefer not to say
May 2026

Summary

Amazon SWE coding round, one question the whole time: implement a path-based getter for nested Maps and Arrays. Felt like a parsing problem dressed up as a data structures question, which I wasn't quite expecting.

Questions Asked (1)

Q1

Implement a get(object, path) function that retrieves a value from a nested structure of objects and arrays using a dot-and-bracket path string (e.g. ab[1].c.d[2][13]). Return the value if the path is valid, otherwise return null.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

My first instinct was to split on dots and then handle brackets separately, which got messy fast.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the path format and edge cases (e.g., empty path, invalid syntax, null/undefined intermediate values). Then, outline a parsing strategy that tokenizes the path into keys and indices, and iterate through the structure, checking at each step if the current value is traversable. Finally, discuss handling of edge cases and potential optimizations like caching parsed paths.

Pro tip: Demonstrate awareness of real-world usage by mentioning that this function is similar to lodash's get, and discuss how you would handle default values or avoid prototype pollution. Also, emphasize writing clean, testable code with clear separation of parsing and traversal logic.

1. Clarify requirements and edge cases

Ask about path syntax, expected return for invalid paths, handling of null/undefined, and whether to support default values. Confirm if the function should be pure and not mutate the input.

2. Design the parsing strategy

Explain how to tokenize the path string into an array of keys and indices, handling dot notation and bracket notation (including quoted keys if applicable). Consider using a regex or a simple state machine.

3. Implement traversal logic

Iterate over the tokens, at each step checking if the current value is an object or array and if the key/index exists. Return null if any step fails.

4. Handle edge cases and errors

Address cases like empty path, non-string path, null/undefined root, and invalid tokens. Decide whether to throw errors or return null based on requirements.

5. Optimize and test

Discuss potential optimizations like caching parsed paths for repeated calls, and outline test cases covering various path formats and edge cases.

Key Points to Mention

  • Path parsing: splitting on dots and brackets, handling array indices and object keys.
  • Traversal safety: checking for null/undefined at each step to avoid TypeErrors.
  • Edge cases: empty path, invalid syntax, non-existent keys, and non-object intermediates.
  • Performance considerations: time complexity O(n) where n is path length, and potential caching of parsed paths.
  • Security: avoiding prototype pollution by not accessing __proto__ or constructor unless explicitly allowed.
  • Testing: unit tests for valid paths, invalid paths, and edge cases like empty objects/arrays.

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