← Pinterest Interview Insights

Pinterest·Software Engineer·Technical Phone Screen·Senior

Senior
May 2026

Summary

Pinterest SWE interview with a meaty data structures question that had a lot more surface area than it looked at first glance. The problem sounds like a simple equality check until you realize sets can nest arbitrarily and order doesn't matter at any level.

Questions Asked (1)

Q1

Write a function to check if two arbitrarily nested sets are equal, where sets are represented as arrays (possibly containing integers or other nested arrays), order doesn't matter, and nesting can go as deep as needed. You also need to pick appropriate data structures, analyze complexity, write unit tests for given cases, and discuss trade-offs between canonicalization, hashing, and recursive approaches.

Algorithms & Data StructuresTechnical Trade-offsSystem Design
Author's notes

I started with the canonicalization idea, basically sort everything recursively into a canonical form and then compare, which works but I fumbled explaining why you need a stable sort order for the nested sets specifically.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and edge cases, then propose a recursive comparison that normalizes each set by sorting or hashing its elements. Discuss trade-offs between canonicalization, hashing, and recursive approaches, and analyze time/space complexity. Finally, outline unit tests covering nested, empty, and duplicate cases.

Pro tip: Mention that you would first ask whether the input can contain duplicates or mixed types, as this affects the equality definition and algorithm choice. Also, note that canonicalization (e.g., sorting) simplifies comparison but may be costly for large sets, while hashing offers average O(n) but requires handling nested structures carefully.

1. Clarify requirements and edge cases

Ask about input constraints: can sets contain duplicates? Are elements only integers or also other types? What about empty sets? Define equality precisely.

2. Choose a comparison strategy

Decide between recursive pairwise comparison, canonicalization (e.g., sorting), or hashing. Consider depth of nesting and potential for cycles (if allowed).

3. Implement the function

Write a recursive function that checks length equality, then for each element in one set, finds a matching element in the other using the same equality logic. Use appropriate data structures (e.g., hash sets for O(1) lookups if elements are hashable).

4. Analyze complexity and trade-offs

Discuss time and space complexity for each approach. For recursive pairwise, worst-case O(n^2) per level; canonicalization O(n log n) per level; hashing O(n) average but requires deep hashing. Mention trade-offs in readability, performance, and handling of unhashable types.

5. Write unit tests and discuss edge cases

List test cases: empty sets, identical nested sets, different order, different nesting, duplicates (if allowed), and large sets. Explain how you would test performance and correctness.

Key Points to Mention

  • Recursive comparison with length check and element matching
  • Canonicalization by sorting or serializing to a canonical form
  • Hashing nested structures (e.g., recursive hashing or Merkle trees)
  • Time and space complexity analysis for each approach
  • Handling of duplicates and mixed types (if applicable)
  • Unit test cases covering edge cases and performance

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