PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates parsing and traversal of nested maps and arrays, robust error handling for missing keys and out-of-bounds indices, and reasoning about algorithmic time and space complexity.

  • medium
  • Amazon
  • Coding & Algorithms
  • Software Engineer

Implement nested object path lookup

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

Implement a function `get(obj, path)` for a nested data structure composed only of maps and arrays. Path rules: - `.` accesses a map key - `[i]` accesses an array index - keys do not contain `.` or brackets - example path syntax: `ab[1].c.d[2][13]` Return the value at the given path. If any key is missing, an index is out of bounds, or the path does not match the actual type at some step, return `null`. Examples: - `get({"a": {"b": [10, 20]}}, "a.b[1]") -> 20` - `get({"a": {"b": [10, 20]}}, "a.b[3]") -> null` Write the function and analyze its time and space complexity.

Quick Answer: This question evaluates parsing and traversal of nested maps and arrays, robust error handling for missing keys and out-of-bounds indices, and reasoning about algorithmic time and space complexity.

Return the value at a dot/bracket path in nested dictionaries and arrays, or None if the path is invalid.

Constraints

  • Map keys do not contain dots or brackets

Examples

Input: ({'a': {'b': [10, 20]}}, 'a.b[1]')

Expected Output: 20

Explanation: Prompt example.

Input: ({'a': {'b': [10, 20]}}, 'a.b[3]')

Expected Output: None

Explanation: Out-of-range index.

Input: ({'ab': [{'c': 5}]}, 'ab[0].c')

Expected Output: 5

Explanation: Object inside array.

Input: ({'a': 1}, 'a.b')

Expected Output: None

Explanation: Type mismatch.

Hints

  1. Tokenize the path, then walk the current object by token type.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Minimum Path Length Through a Grid With One Allowed Cell Conversion - Amazon (medium)
  • Circular Drone Hub Delivery Route - Amazon (hard)
  • Leaf Domain Cumulative Scores - Amazon (medium)
  • Kth Largest Perfect Binary Subtree - Amazon (medium)
  • Find Conflicting Events - Amazon (medium)