Do Partial Courier Reports Pin Down a Unique Stop Order

Last updated: November 29, 2026

Quick Overview

A batched delivery has n stops labeled 1..n; couriers report partial sequences of stops in the order they were visited. Determine whether these reports imply exactly one possible full visiting order, and return it, or None if the order is ambiguous or contradictory.

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

0

0

0 solved


A batched delivery has n stops labeled 1..n; couriers report partial sequences of stops in the order they were visited. Determine whether these reports imply exactly one possible full visiting order, and return it, or None if the order is ambiguous or contradictory.

Reconstructing what actually happened on a multi-stop Uber Eats batch from fragmentary logs is a real support and fraud-review task. The interviewer checks that you turn sequences into precedence edges and use the 'exactly one ready node at a time' property of Kahn's algorithm to test uniqueness.

What the Interviewer Expects
  • Convert each report into consecutive precedence edges
  • Run Kahn's algorithm and check the ready queue never holds more than one node
  • Detect contradictions (cycles) and missing stops
  • Avoid double-counting duplicate edges
  • Explain why uniqueness is equivalent to a Hamiltonian path in the DAG
Key Topics to Cover
topological sort
uniqueness check
Kahn's algorithm
sequence reconstruction
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
  • How would you return the number of possible orders for small n?
  • What if some reports may be wrong and you want to drop the fewest reports to make the order consistent?
  • How would you handle reports that skip stops (non-consecutive observations)?
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: n, reports list of lists of stop labels.
  • Each adjacent pair in a report gives a before b.
  • Output: the unique order as a list, or None....
High-Level Design

Build a DAG from consecutive pairs, deduplicating edges with a set so in-degrees are accurate. A topological order is unique exactly when, at every step of Kahn's algorithm, exactly one node has in-de...


Submit Your Answer
Markdown supported