← Pinterest Interview Insights
The board co-membership part is what gets you.
Model the problem as an unweighted graph where each pin is a node, and edges exist between pins that are directly connected or share a board. Then run BFS from the source pin to find the shortest path length to the target pin, returning -1 if unreachable. Emphasize that BFS guarantees the shortest path in unweighted graphs.
Pro tip: Mention that you can optimize by precomputing board memberships and using a visited set to avoid cycles, and discuss how this scales if the graph is huge (e.g., using bidirectional BFS or partitioning).
Ask about input size, whether boards can have many pins, if edges are bidirectional, and if multiple boards can share pins. Confirm that adjacency includes same-board pins.
Represent each pin as a node. Add edges for direct pin-to-pin connections and for every pair of pins on the same board (or use a board node to avoid O(n^2) edges).
Since edges are unweighted, BFS from the source pin gives the shortest path length. Use a queue and a visited set to track distances.
Consider if source equals target (distance 0), disconnected components (return -1), and analyze time/space complexity. Discuss trade-offs of explicit vs implicit graph representation.
For large-scale systems, mention bidirectional BFS, precomputation, caching, or distributed graph processing. Relate to Pinterest's scale and real-time constraints.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.