Restore the Array From Adjacent Pairs
A medium-tier problem at 75% community acceptance, tagged with Array, Hash Table, Depth-First Search. Reported in interviews at Robinhood and 0 others.
Restore the Array From Adjacent Pairs is a medium-difficulty problem that shows up in Robinhood interviews. You're given pairs of integers that represent adjacent elements in an unknown array, and you have to reconstruct the original sequence. It sounds simple until you realize the pairs are shuffled and you don't know the start or end. The acceptance rate sits around 75 percent, which means most candidates who attempt it solve it, but that's because they either prep it or they hit it cold and blank. StealthCoder is the hedge for that second scenario: invisible during your live assessment, it surfaces a working reconstruction in seconds.
Companies that ask "Restore the Array From Adjacent Pairs"
Restore the Array From Adjacent Pairs is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.
Get StealthCoderThe trick is building a graph where each number maps to its neighbors, then finding the start point (degree 1 or 0) and walking the chain. A hash table stores the adjacency list, and you traverse using DFS or iterative backtracking to visit each neighbor exactly once. Candidates often miss that the start must have only one neighbor, or they build the graph correctly but fail to handle the traversal order and backtrack cleanly. The problem lives at the intersection of Array, Hash Table, and Depth-First Search, and the hard part isn't the graph construction, it's recognizing the start condition and not getting lost in the DFS logic. If you freeze on the approach during the OA, StealthCoder runs the solution invisibly and you move forward.
Pattern tags
You know the problem.
Make sure you actually pass it.
Restore the Array From Adjacent Pairs recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Restore the Array From Adjacent Pairs interview FAQ
How do I know where the array starts?+
The start element appears in exactly one pair. Build your adjacency hash table first, then scan for any number with degree 1. That's your anchor. If all numbers have degree 2, it's a cycle and you pick any start, but this problem guarantees a linear array.
Why can't I just sort the pairs?+
Sorting doesn't work because pairs are unordered internally and the list is scrambled. You need a graph structure to capture which numbers are adjacent to which. Hash table adjacency is the only reliable way.
Is this really asked at top companies?+
Robinhood has reportedly asked it. It's not as common as two-pointer or sliding window, but it's precisely the type of medium-difficulty graph problem that backend and infrastructure teams use to filter for problem-solving depth in live rounds.
What's the time and space complexity?+
Time is O(n) for building the graph and O(n) for the traversal, so O(n) overall. Space is O(n) for the hash table and recursion stack. No way around it, and interviewers expect you to state this upfront.
Do I need DFS or can I use BFS?+
Either works. DFS is simpler to code because you can use recursion and backtrack naturally. BFS requires a queue and careful bookkeeping. Most candidates find DFS cleaner. The problem lists DFS as a topic, so that's your hint.
Want the actual problem statement? View "Restore the Array From Adjacent Pairs" on LeetCode →