Check Whether Partial Scan Logs Pin Down a Unique Route Order

Last updated: November 29, 2026

Quick Overview

A package route visits hubs 1..n in a proposed order, and each scan log gives an ordered subsequence of hubs the package passed. Return whether the logs together determine the proposed route as the only possible order.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


A package route visits hubs 1..n in a proposed order, and each scan log gives an ordered subsequence of hubs the package passed. Return whether the logs together determine the proposed route as the only possible order.

Amazon Logistics reconstructs package journeys from partial scan data, and this asks whether that evidence is conclusive. The interviewer wants a topological sort where the ready set has size exactly one at every step, and a clear explanation of why that implies uniqueness.

What the Interviewer Expects
  • Build edges from consecutive hubs in each log
  • Run Kahn's algorithm and fail as soon as two hubs are simultaneously ready
  • Compare the produced order to the proposed route
  • Validate hub ids in the logs
  • O(n + total log length)
Key Topics to Cover
topological sort
uniqueness
sequence reconstruction
Kahn's algorithm
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Why does uniqueness of the topological order mean a Hamiltonian path exists in the DAG?
  • How would you check uniqueness without running Kahn, by looking at consecutive pairs?
  • What if some logs are noisy and might be wrong?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: route, a permutation of 1..n, and scans, a list of subsequences. Output: True only if the only order consistent with all scans is route. Ask whether every hub must appear in some log (i...

High-Level Design

Each log contributes edges between consecutive hubs. The order is unique exactly when, during Kahn's algorithm, the queue never holds more than one node: if two hubs are ready at once, either could go...


Submit Your Answer
Markdown supported