← Pinterest Interview Insights

Pinterest·Software Engineer·Technical Phone Screen·Senior

Senior
May 2026

Summary

Pinterest SWE interview that was basically a graph problem dressed up in Pinterest-flavored language. Boards, pins, edges. The core ideas are standard but the multi-query structure kept things interesting.

Questions Asked (4)

Q1

Given a set of boards (each containing pins) and weighted edges between pins, implement a `connected(pin1, pin2)` function that returns true if there is any path between the two pins, treating both direct edges and shared board membership as connectivity.

Algorithms & Data StructuresSystem Design
Author's notes

Union-Find felt like the right call here.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a graph where pins are nodes, and edges represent direct connections or shared board membership (by connecting all pins on the same board). Then use Union-Find (Disjoint Set Union) to efficiently answer connectivity queries, as it supports near-constant time union and find operations. Alternatively, use BFS/DFS for each query if the graph is static and queries are few, but Union-Find is preferred for scalability.

Pro tip: Clarify upfront whether the graph is static or dynamic (edges added over time) and the expected query volume; this determines whether to preprocess with Union-Find or use on-the-fly traversal. Also, mention that shared board membership can be modeled by adding a virtual node per board connected to all its pins, which simplifies the graph and reduces edge count.

1. Clarify requirements and constraints

Ask about the number of pins, boards, edges, and queries, as well as whether the graph is static or dynamic. This informs the choice of algorithm and data structures.

2. Model the graph

Represent pins as nodes. For each board, either connect all pins on that board with edges (forming a clique) or introduce a virtual board node connected to each pin to avoid O(n^2) edges.

3. Choose the algorithm

For static graphs with many queries, use Union-Find to preprocess connected components. For dynamic graphs, consider Union-Find with path compression and union by rank. For few queries, BFS/DFS per query is acceptable.

4. Implement and optimize

Implement the chosen approach, ensuring efficient union and find operations. Discuss trade-offs: Union-Find is O(α(n)) per operation, while BFS/DFS is O(V+E) per query.

5. Test and validate

Walk through examples, including edge cases like pins on the same board, disconnected pins, and cycles. Verify correctness and discuss potential optimizations.

Key Points to Mention

  • Union-Find (Disjoint Set Union) with path compression and union by rank for near-constant time operations.
  • Modeling shared board membership: either connect all pins on a board (clique) or use a virtual board node to reduce edges.
  • Time and space complexity: Union-Find preprocessing O(E α(N)), query O(α(N)); BFS/DFS per query O(V+E).
  • Trade-offs between preprocessing all connections vs. on-the-fly traversal based on query frequency.
  • Handling dynamic graphs: if edges are added over time, Union-Find supports incremental unions efficiently.
  • Edge cases: pins on the same board, isolated pins, multiple boards, and cycles.

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

Q2

Implement `shortestPinDistance(pin1, pin2)` that returns the shortest weighted distance between two pins, where shared board membership counts as a zero-cost edge.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Dijkstra with the board memberships modeled as zero-weight edges between co-board pins.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a graph where pins are nodes, weighted edges represent direct connections, and zero-cost edges represent shared board memberships. Then run Dijkstra's algorithm to find the shortest path between the two pins, ensuring the graph construction handles potentially large numbers of shared boards efficiently.

Pro tip: Clarify upfront whether the graph is static or dynamic, and discuss how to optimize for repeated queries by precomputing distances or using bidirectional search. This shows you think about real-world scalability and trade-offs.

1. Clarify requirements and constraints

Ask about graph size, edge weights, whether the graph is directed, and if queries are frequent. This ensures you design the right solution and demonstrates thoroughness.

2. Model as a graph

Represent pins as nodes. Add weighted edges for direct connections and zero-cost edges between pins that share a board. Consider using a bipartite graph with board nodes to avoid O(n^2) edges.

3. Choose shortest path algorithm

Since edge weights are non-negative, Dijkstra's algorithm is optimal. Mention alternatives like BFS if all weights were equal, but here weights vary.

4. Optimize for performance

Discuss using a priority queue for Dijkstra, and if multiple queries, consider precomputing all-pairs shortest paths or using bidirectional Dijkstra. Also address memory usage for large graphs.

5. Analyze complexity and trade-offs

State time and space complexity, and compare with alternative approaches like Floyd-Warshall. Highlight trade-offs between preprocessing and query time.

Key Points to Mention

  • Graph modeling with pins as nodes and boards as zero-cost connectors
  • Dijkstra's algorithm for non-negative weighted graphs
  • Using a bipartite graph to avoid quadratic edge explosion
  • Time complexity O(E log V) with a binary heap
  • Handling multiple queries with precomputation or caching
  • Edge cases: disconnected pins, self-loops, and negative weights (if any)

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

Q3

Implement `shortestBoardDistance(boardA, boardB)` that returns the minimum shortest-pin-distance across all pairs where one pin is from boardA and the other is from boardB.

Algorithms & Data StructuresSystem Design
Author's notes

Multi-source Dijkstra.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the input format and distance metric, then propose an efficient algorithm such as a sweep line or divide-and-conquer to find the closest pair across two sets. Discuss time/space complexity and edge cases, and consider scalability for large boards.

Pro tip: Mention that you would first check if the boards are sorted by one coordinate to enable a sweep line, and that you would handle duplicate points and collinear cases gracefully.

1. Clarify the problem

Ask about the representation of pins (e.g., coordinates), the distance metric (Euclidean, Manhattan), and constraints like board size and number of pins.

2. Choose an algorithm

Propose an efficient approach: for 1D, sort and merge; for 2D, use divide-and-conquer or sweep line to achieve O(n log n) time.

3. Handle edge cases

Consider empty boards, single pin, duplicate pins, and large inputs. Discuss how your algorithm handles these.

4. Analyze complexity

State the time and space complexity of your solution and compare with brute force O(n*m).

5. Optimize and scale

If needed, discuss further optimizations like spatial indexing (k-d tree) or parallelization for very large datasets.

Key Points to Mention

  • Distance metric (Euclidean vs Manhattan) and its impact on algorithm choice
  • Divide-and-conquer or sweep line for O(n log n) time
  • Handling edge cases: empty boards, single pin, duplicates
  • Time and space complexity analysis
  • Scalability considerations for large boards (e.g., spatial indexing)
  • Correctness proof or invariant of the chosen algorithm

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

Q4

Discuss your data structure choices for the above queries and analyze their time and space complexity.

Technical Trade-offsAlgorithms & Data Structures
Author's notes

Union-Find for connectivity is basically O(alpha(n)) per query after setup.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by restating the problem and the queries to ensure alignment, then systematically justify each data structure choice by comparing alternatives and analyzing time/space complexity. Emphasize trade-offs and how your choices optimize for the expected workload and constraints.

Pro tip: Quantify the impact of your choices using real-world metrics (e.g., Pinterest's scale) and mention how you'd validate with profiling or load testing. This shows you think beyond theoretical complexity to production performance.

1. Clarify the problem and queries

Restate the problem and the specific queries to ensure you understand the requirements, including data size, access patterns, and performance goals.

2. List candidate data structures

Enumerate plausible data structures (e.g., arrays, hash maps, trees, heaps, graphs) and briefly note their strengths and weaknesses for the given queries.

3. Justify your choices

For each query, explain why you selected a particular data structure, comparing it to alternatives in terms of time and space complexity and practical factors like cache locality.

4. Analyze time and space complexity

Provide Big-O analysis for each operation (insert, delete, search, etc.) and overall space usage, considering average and worst cases.

5. Discuss trade-offs and optimizations

Highlight trade-offs (e.g., time vs. space, simplicity vs. performance) and mention potential optimizations or alternative approaches if constraints change.

Key Points to Mention

  • Time complexity of each operation (e.g., O(1) for hash map lookup, O(log n) for balanced BST)
  • Space complexity and overhead (e.g., pointers in linked structures, load factor in hash tables)
  • Trade-offs between different data structures (e.g., hash map vs. tree for range queries)
  • Consideration of real-world factors like memory locality, concurrency, and persistence
  • How the choice aligns with Pinterest's scale and specific use case (e.g., high read throughput)
  • Potential alternatives and when they might be preferable (e.g., using a trie for prefix searches)

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