Problem · Graph
Reconstruct Landmark Journey
A traveler visited a series of unique landmarks on a journey. Unfortunately, their travel journal was damaged, and they can no longer remember the exact order of their visits. However, they do have a collection of photos, each showing exactly two landmarks that were visited consecutively. Either landmark could have been visited first.
Given the collection of photos represented as pairs of landmark IDs in travelPhotos, help the traveler reconstruct the complete journey. Each landmark was visited exactly once, and for every consecutive pair of landmarks in the journey, there exists a photo containing both landmarks.
You may reconstruct the journey in either forward or reverse order; both are considered correct.
Examples
01 · Example 1
travelPhotos = [[3, 5], [1, 4], [2, 4], [1, 5]] return = [3, 5, 1, 4, 2]
- The photos show that landmarks
3and5were visited consecutively, as were1and4,2and4, and1and5. - The journey
[3, 5, 1, 4, 2]contains each of those consecutive landmark pairs.
More Capital One problems
- Compare Counts Around PivotOA · Seen Jun 2026
- Count House Segments After DestructionOA · Seen May 2026
- Count Numbers with Even Number of DigitsOA · Seen May 2026
- Laser Robot Safe PathOA · Seen May 2026
- Longest Same-Character SubstringOA · Seen May 2026
- Cyclic Shift to Strictly Descending ArrayOA · Seen May 2026
- Dynamic Wall Building and Range QueryOA · Seen May 2026
- Queue Check-in Simulation with Capacity LimitOA · Seen May 2026
public int[] solution(int[][] travelPhotos) {
// write your code here
}travelPhotos[[3, 5], [1, 4], [2, 4], [1, 5]]
expected[3, 5, 1, 4, 2]
checking account