Reconstruct Landmark Journey
Reported by candidates from TikTok's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt on TikTok's Reconstruct Landmark Journey, reported July 2026, is treating the pairs like a sorted list instead of a graph. You get unordered, undirected edges that form one simple path, and you have to rebuild the order. It's an adjacency map plus a walk. Nothing exotic. But the tie-break on which endpoint you start from trips people who skim. If you've got the invite and 48 hours, this is learnable tonight. And if you blank mid-assessment, StealthCoder runs invisibly on your desktop as a safety net.
The problem
A traveler visited a series of unique landmarks but no longer remembers the exact order. Each pair in travelPhotos shows two landmarks that were visited consecutively; either landmark may have been visited first. Reconstruct the complete journey. Every landmark was visited exactly once, and every adjacent pair in the result must correspond to one supplied photo. The photos are guaranteed to describe one simple path containing every landmark. Function solution(travelPhotos: int[][]) → int[] Examples Example 1 travelPhotos = [[3,5],[1,4],[2,4],[1,5]] return = [3,5,1,4,2] The pairs connect the path 3 - 5 - 1 - 4 - 2. The endpoints are 3 and 2; 3 is encountered first in the input, so the deterministic result starts there. Constraints 1 <= travelPhotos.length Every element of travelPhotos contains exactly two distinct landmark IDs. The undirected pairs form one simple path and contain no duplicate edge.
Reported by candidates. Source: FastPrep
Pattern and pitfall
Build a hash map from each landmark to its neighbors. In a simple path, exactly two nodes have degree 1. Those are the endpoints. The example says the deterministic start is the endpoint encountered first in the input, so scan travelPhotos in order and pick the first landmark with degree 1. Then walk: keep a previous node, move to the neighbor that isn't previous, and stop when you've placed every landmark. The common pitfall is picking the start by smallest ID or by map iteration order, which breaks the expected output. Another is forgetting the single-photo case, where both nodes have degree 1 and you still pick the first one seen. Runtime is O(n) time and space. If the walk logic or the start rule slips away under pressure, StealthCoder is the hedge during the live OA, reading the problem and giving you a working solution.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Reconstruct Landmark Journey cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as restore the array from adjacent pairs. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass TikTok's OA.
TikTok reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Reconstruct Landmark Journey FAQ
What's the trick in Reconstruct Landmark Journey?+
Treat the pairs as an undirected graph. Build an adjacency map, find an endpoint (degree 1), then walk the path by always stepping to the neighbor that isn't the node you just came from. That's the whole solution, and it runs in linear time.
How do I pick the starting landmark?+
Scan travelPhotos in input order, flattening each pair left to right, and take the first landmark whose degree is 1. The example confirms this: 3 and 2 are endpoints, and 3 shows up first, so the answer starts at 3.
How hard is this really?+
Easy to medium. There's no clever algorithm, just clean graph bookkeeping. Most failures come from the start-node rule, off-by-one in the walk, or mishandling a single-photo input. If you've done adjacency maps before, it's a 15 minute problem.
What edge cases should I test?+
Test one photo only, like [[1,2]], where the result is [1,2]. Test a photo order where the first pair is in the middle of the path. Test reversed pairs like [5,3] versus [3,5]. Landmark IDs that aren't contiguous also matter, so use a hash map, not an array.
How do I prepare for this in 48 hours?+
Write the adjacency map and path walk from scratch twice, once in your assessment language. Then solve a couple of related graph traversal problems. Focus on the degree-1 endpoint idea and the previous-node trick. Don't spend time on advanced graph algorithms, they won't show up here.