Check Whether Event Logs Pin Down a Single Global Ordering

Last updated: November 29, 2026

Quick Overview

Several client logs each record a subsequence of event ids in the order observed. Given the event ids 1..n and these logs, return True if exactly one global ordering of all n events is consistent with every log, and False otherwise.

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

0

0

0 solved


Several client logs each record a subsequence of event ids in the order observed. Given the event ids 1..n and these logs, return True if exactly one global ordering of all n events is consistent with every log, and False otherwise.

A Meta onsite question in the style of reasoning about distributed client logs from Messenger, where you want to know if partial observations fully determine the true order. The interviewer checks that you turn consecutive pairs into edges and recognize that a topological order is unique exactly when Kahn's queue never holds more than one node.

What the Interviewer Expects
  • Build edges only from consecutive pairs within each log
  • Run Kahn's algorithm and fail if the queue ever has two candidates
  • Also fail on cycles or events never mentioned
  • Avoid enumerating all topological orders
  • State O(n + total log length) time
Key Topics to Cover
topological sort
uniqueness
Hamiltonian path in DAG
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 are consecutive pairs enough, rather than all pairs in each log?
  • How would you return a minimal set of extra pairs that would make the order unique?
  • What if logs can contain errors and you want the order that agrees with the most logs?
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 and logs, a list of lists of event ids in observed order.
  • Output: True if exactly one permutation of 1..n respects every log, else False.
  • An event that never appears in any lo...
High-Level Design

Each log implies log[i] before log[i+1]. Transitive pairs inside a log follow automatically, so consecutive edges suffice.

A DAG has a unique topological order if and only if, at every step of Ka...


Submit Your Answer
Markdown supported