Algorithms & Data Structureshard
Collect Pins from Reachable Boards
On Pinterest, a board contains pins, and the same pin can be saved to many boards. From any board you can "hop" to any other board that shares at least one pin with it.
Given a mapping boards (board id to the pin ids on that board) and a starting board, return all pins reachable from the start — i.e., every pin on every board in the start board's connected component.
Example:
boards = {
"B1": ["p1", "p2"],
"B2": ["p2", "p3"], // reachable from B1 via shared p2
"B3": ["p4"], // not reachable
"B4": ["p3", "p5"], // reachable from B2 via shared p3
"B5": [],
}
collectReachablePins(boards, "B1") -> ["p1", "p2", "p3", "p5"]For the judge, return the reachable pins as a sorted array. A missing start board returns an empty array.