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
November 29, 20260
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
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- 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 ProblemsSample Answer
Requirements
- Input:
nandlogs, a list of lists of event ids in observed order. - Output:
Trueif exactly one permutation of1..nrespects every log, elseFalse. - 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...