Order Nightly Payout Batch Jobs With Dependency Checks
Last updated: November 29, 2026
Quick Overview
Given the list of nightly settlement jobs and dependency pairs (before, after), return a valid run order that picks the alphabetically smallest ready job at each step, plus the list of jobs that can never run because of a cycle.
PayPal
November 29, 20260
0
0 solved
Given the list of nightly settlement jobs and dependency pairs (before, after), return a valid run order that picks the alphabetically smallest ready job at each step, plus the list of jobs that can never run because of a cycle.
Settlement at PayPal runs as a chain of batch jobs (FX rate snapshot, ledger close, payout file generation, reconciliation reports). This topological sort question checks Kahn's algorithm, deterministic tie-breaking with a heap, and graceful reporting of cycles instead of crashing.
What the Interviewer Expects
- Build in-degree counts and adjacency lists
- Use Kahn's algorithm with a min-heap for deterministic order
- Report jobs blocked by cycles rather than returning nothing useful
- Validate unknown job names in dependencies
- Give O((V + E) log V) complexity
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 run independent jobs in parallel and compute the minimum total wall-clock time given durations?
- How would you print the actual cycle for an on-call engineer?
- What happens when one job fails mid-night; which downstream jobs should be skipped?
- How would you incrementally add a dependency without recomputing everything?
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 (unique names) and deps where (a, b) means a must finish before b starts. Output a tuple (order, blocked): order is a valid execution order using the smallest available name at ea...
High-Level Design
Kahn's algorithm: compute in-degree, start with all zero in-degree jobs, repeatedly pop one, append it to the order and decrement its children. A min-heap instead of a queue gives the alphabetical tie...