The length part I got pretty quickly, topological sort plus a running max.
Model the tasks as a weighted DAG where edge weights are task durations, then compute the longest path using topological order dynamic programming. To reconstruct the actual sequence, store predecessor pointers for each node and backtrack from the node with the maximum distance.
Pro tip: Clarify upfront whether the graph is guaranteed acyclic and whether multiple critical paths exist—if so, ask which one to output or if any is acceptable. Also, mention that you can handle multiple test graphs by wrapping the algorithm in a loop and resetting state.
Confirm how tasks, dependencies, and durations are represented (e.g., adjacency list, edge list) and whether the graph is guaranteed a DAG. Ask about output format for multiple graphs and tie-breaking rules.
Construct an adjacency list with edge weights equal to task durations. Compute in-degrees for all nodes to prepare for topological sorting.
Perform topological sort (Kahn's algorithm or DFS). Process nodes in topological order, updating the longest distance to each neighbor and recording the predecessor that gives the maximum.
Identify the node with the maximum distance (critical path length). Backtrack using predecessor pointers to build the sequence of tasks from start to end.
Loop over each test graph, resetting data structures. Consider edge cases: empty graph, single node, disconnected components, and multiple critical paths.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.