PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCareers
|Home/Coding & Algorithms/Pinterest

Reconstruct route from unordered travel tickets

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of directed graph concepts and sequence reconstruction, assessing the ability to reason about ordered relationships and one-to-one incoming/outgoing connections between nodes.

  • medium
  • Pinterest
  • Coding & Algorithms
  • Software Engineer

Reconstruct route from unordered travel tickets

Company: Pinterest

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are given a list of directed travel tickets, each represented as a pair `[from, to]` (city names are strings), e.g. `[["A","B"],["B","C"], ...]`. The tickets form exactly one valid trip that visits cities in a single chain (no branching): - Every city has **at most one outgoing** ticket and **at most one incoming** ticket. - All tickets belong to the same trip. - The starting city is **not given**. Return the full ordered itinerary as a list of cities, e.g. given `[["A","B"],["B","C"]]`, return `["A","B","C"]`. **Constraints** - `1 <= tickets.length <= 2e5` - City names are non-empty strings. - The input is guaranteed to form one valid chain. **Output** - A list of cities of length `tickets.length + 1` representing the reconstructed route.

Quick Answer: This question evaluates understanding of directed graph concepts and sequence reconstruction, assessing the ability to reason about ordered relationships and one-to-one incoming/outgoing connections between nodes.

Related Interview Questions

  • Design Hierarchical Permission Checks - Pinterest (medium)
  • Implement weighted random choice - Pinterest (medium)
  • Solve five hard algorithm problems - Pinterest
  • Sample a string by real-valued scores - Pinterest (hard)
  • Find First Prefix-Matching Word - Pinterest (medium)
Pinterest logo
Pinterest
Jan 6, 2026, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
8
0
Loading...

You are given a list of directed travel tickets, each represented as a pair [from, to] (city names are strings), e.g. [["A","B"],["B","C"], ...].

The tickets form exactly one valid trip that visits cities in a single chain (no branching):

  • Every city has at most one outgoing ticket and at most one incoming ticket.
  • All tickets belong to the same trip.
  • The starting city is not given .

Return the full ordered itinerary as a list of cities, e.g. given [["A","B"],["B","C"]], return ["A","B","C"].

Constraints

  • 1 <= tickets.length <= 2e5
  • City names are non-empty strings.
  • The input is guaranteed to form one valid chain.

Output

  • A list of cities of length tickets.length + 1 representing the reconstructed route.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Pinterest•More Software Engineer•Pinterest Software Engineer•Pinterest Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • Careers
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.