Find the Critical Path of a Nightly Mainframe Batch Schedule
Last updated: November 29, 2026
Quick Overview
Given batch jobs with durations and upstream dependencies, compute the earliest time the whole nightly run can finish with unlimited parallel slots, and return the chain of jobs that determines that time. Report an error if the dependencies contain a cycle.
Cognizant
November 29, 20260
0
0 solved
Given batch jobs with durations and upstream dependencies, compute the earliest time the whole nightly run can finish with unlimited parallel slots, and return the chain of jobs that determines that time. Report an error if the dependencies contain a cycle.
Cognizant runs many mainframe modernization programs where JCL batch chains are rebuilt as orchestrated jobs on cloud schedulers, and the first question is always whether the new run fits the batch window. This tests topological sorting, longest path in a DAG, and cycle detection with a clear error.
What the Interviewer Expects
- Builds the graph and in-degree map, validating unknown dependencies
- Uses Kahn's algorithm so cycles are detected by leftover nodes
- Computes each job's start as the max finish of its parents
- Tracks the parent that set the start to reconstruct the critical path
- Explains O(V + E) cost
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
- Only 3 jobs can run at once. Is the problem still easy? What heuristic would you use?
- How would you compute slack for every job, so the team knows which jobs can slip?
- A job's duration varies night to night. How would you estimate the probability of missing the window?
- How would you rerun only the downstream jobs after one job fails?
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: jobs maps a name to (duration, [upstream names]). Every job starts once all upstream jobs finish; parallelism is unlimited. Output: the makespan (latest finish) and the critical path (the d...
High-Level Design
Run Kahn's algorithm. Each job's start is the maximum finish time among its parents; its finish is start plus duration. When a parent raises a child's start, record that parent as the child's critical...