Product catalog lookup: item attributes plus a cycle-safe tree of related items
Company: Sierra
Role: Product Manager
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Other
A merchandise catalog is stored as a nested Python dictionary. Given an item, return that item's attributes, then follow its related items recursively and build the full tree of relationships rooted at the item.
```hint Settle the references first
Before writing any recursion, decide how a related item is referenced and what your tree should contain when following references leads back to an item you are already expanding.
```
### Clarifying Questions
- How is a related item referenced: by an ID that has to be looked up elsewhere in the catalog, or nested inline under its parent?
- Where do items sit in the nesting (for example under categories and subcategories), and can the same ID appear in two places?
- Can relationships loop back (A relates to B and B relates to A), and how should a repeat appear in the tree?
- What should happen when a related ID is missing from the catalog?
### What a Strong Answer Covers
- Locating the item inside an arbitrarily nested structure, with a deliberate plan for lookups (index once versus search every time)
- A recursive traversal that builds the tree in an explicitly defined output shape
- Handling of cycles, items shared by several parents, missing references and malformed entries
- Complexity, the recursion-depth limit, and an iterative alternative
- Tests covering a leaf item, a shared related item, a cycle and a missing reference
### Follow-up Questions
- The catalog grows to millions of items and the related-item chains get long. What breaks first in your solution, and what do you change?
- Two related items both point to the same accessory. Should it appear twice in the tree or once, and how does each choice affect the output size?
- How would you limit the tree to a maximum depth?
Overview: A Python coding exercise from a Sierra product manager interview: look up an item in a nested merchandise catalog dictionary, return its attributes, and recursively follow its related items to build a full relationship tree. It tests recursion, dictionary traversal, and handling of cycles and missing references.