← Pinterest Interview InsightsSoftware Engineer

Pinterest·Software Engineer·Onsite - System Design / Architecture·Senior

SeniorPrefer not to say
Jun 2026

Summary

Pinterest system design round for a software engineer role, one question the whole time, pretty deep dive into data structures and runtime guarantees. Felt like a solid problem but I kept second-guessing myself on the leaderboard part.

Questions Asked (1)

Q1

Design a data structure to model the state of an escape-room game. Player movement and room lookups must each be O(1), and the leaderboard must return players sorted by position descending in O(N + k), with ties broken by who entered the room first.

Algorithms & Data StructuresSystem DesignTechnical Trade-offs
Author's notes

I started with a hash map from player id to position, which covers the O(1) movement and lookup requirements fine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the requirements and constraints, then propose a composite data structure: a hash map for O(1) player lookups and a doubly linked list to maintain insertion order for tie-breaking. For the leaderboard, use bucket sort by position (assuming positions are bounded) to achieve O(N + k) time, iterating buckets in descending order and within each bucket preserving insertion order via the linked list.

Pro tip: Mention that the leaderboard's O(N + k) complexity relies on positions being integers within a known range; if positions can be arbitrary, you'd need a different approach like a balanced BST with O(N log N) or a radix sort variant. This shows you understand the trade-offs and don't blindly apply bucket sort.

1. Clarify requirements and constraints

Ask about the range of positions, whether players can share positions, and how often the leaderboard is queried. Confirm that O(1) movement and lookup means constant-time updates to player state and retrieval by player ID.

2. Design core data structures

Use a hash map (player ID -> player object) for O(1) lookups. For movement, update the player's position in O(1) by also maintaining a doubly linked list ordered by entry time to handle tie-breaking.

3. Implement leaderboard with bucket sort

Create an array of buckets indexed by position (if positions are bounded). Each bucket holds a list of players at that position, ordered by entry time. To generate the leaderboard, iterate buckets from highest to lowest position, concatenating players.

4. Analyze complexity and trade-offs

Explain that movement and lookup are O(1) due to hash map and linked list updates. Leaderboard generation is O(N + k) where N is number of players and k is position range, because we visit each bucket and each player once. Discuss alternatives if positions are unbounded.

5. Handle edge cases and optimizations

Consider empty leaderboard, players with same position, and dynamic position ranges. Mention that if k is large, bucket sort may be inefficient, and a comparison sort with tie-breaking could be O(N log N).

Key Points to Mention

  • Hash map for O(1) player lookup and movement updates
  • Doubly linked list to maintain insertion order for tie-breaking
  • Bucket sort by position for O(N + k) leaderboard generation
  • Assumption of bounded integer positions for bucket sort
  • Trade-offs: bucket sort vs. comparison sort when position range is large
  • Handling ties by entry time using linked list order within buckets

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