Deterministic Order for Dependent Ranking Pipeline Jobs
Last updated: November 29, 2026
Quick Overview
Given a set of offline jobs for a ranking pipeline and their dependencies (job A must finish before job B), return a valid run order that is the lexicographically smallest among all valid orders, or report that the dependencies contain a cycle.
0
0
0 solved
Given a set of offline jobs for a ranking pipeline and their dependencies (job A must finish before job B), return a valid run order that is the lexicographically smallest among all valid orders, or report that the dependencies contain a cycle.
Pinterest runs large daily workflows that ingest engagement logs, build features, train home feed models, and evaluate them. This question checks topological sorting plus a determinism requirement, which matters when on-call engineers need reproducible schedules to debug a broken pipeline.
What the Interviewer Expects
- Builds in-degree counts and adjacency lists
- Uses Kahn's algorithm with a min-heap to get the smallest order
- Detects a cycle by comparing the output length to the job count
- States O((V + E) log V) complexity
- Discusses what to report to the user when there is a cycle
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
- How would you return the jobs that form the cycle?
- If each job has a duration and unlimited workers, what is the earliest finish time of the whole pipeline?
- How would you rerun only jobs downstream of one that failed?
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: job names and (before, after) pairs. All names in deps appear in jobs.
- Output: smallest valid order by string comparison at each step, or None if no valid order exists....
High-Level Design
Kahn's algorithm repeatedly removes a job with no unmet dependencies. Using a min-heap instead of a queue for the ready set means we always pick the smallest available name, which yields the lexicogra...