Order Yahoo Ad Reporting Jobs and Report the Exact Dependency Cycle
Last updated: November 29, 2026
Quick Overview
Given a set of nightly ad reporting jobs and dependency pairs (a must finish before b), return a valid run order that is lexicographically smallest among valid orders. If no order exists, report one concrete cycle of job names.
Yahoo
November 29, 20260
0
0 solved
Given a set of nightly ad reporting jobs and dependency pairs (a must finish before b), return a valid run order that is lexicographically smallest among valid orders. If no order exists, report one concrete cycle of job names.
Yahoo's advertising data platform runs large DAGs of aggregation jobs for advertiser reports and billing. Interviewers ask this to check topological sort fluency plus the practical detail of surfacing the actual cycle so an on-call engineer can fix the config.
What the Interviewer Expects
- Build adjacency lists and in-degrees, validating unknown job names
- Use Kahn's algorithm with a min-heap for deterministic smallest order
- Detect a cycle when fewer than all jobs are emitted
- Recover an explicit cycle with three-color DFS
- State O((V+E) log V) 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
- How would you compute the earliest finish time if each job has a duration and unlimited workers?
- How would you schedule with only W parallel workers?
- If one job fails, which downstream jobs must be skipped?
- How would you detect cycles incrementally as engineers add edges?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Inputs: jobs (names) and deps as (before, after) pairs. Output: an order where every edge goes forward, choosing the alphabetically smallest available job whenever there is a choice. On a cycle,...
High-Level Design
- Build
adjandindeg; an edge to a job not in the list is a config error. - Kahn's algorithm with a min-heap instead of a queue gives the smallest order.
- If the output is shorter than
jobs...