Order Dependent Tasks by Earliest Due Date First
Last updated: November 29, 2026
Quick Overview
Given tasks with due dates and 'blocked by' dependencies, return an order to work through them where every blocker comes first and, among tasks that are unblocked, the one due soonest goes next. Return None if the dependencies contain a cycle.
Asana
November 29, 20260
0
0 solved
Given tasks with due dates and 'blocked by' dependencies, return an order to work through them where every blocker comes first and, among tasks that are unblocked, the one due soonest goes next. Return None if the dependencies contain a cycle.
Task dependencies are a core Asana feature in timeline and list views, and a suggested work order is a natural extension of My Tasks. The interviewer checks topological sort, the tweak of using a priority queue instead of a FIFO, and cycle detection.
What the Interviewer Expects
- Builds an adjacency list and in-degree map from the dependency pairs
- Uses Kahn's algorithm with a min-heap keyed by due date then id
- Detects cycles by comparing output length to task count
- Deduplicates repeated dependency pairs
- States complexity with the heap factor
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 report which tasks are in the cycle?
- How would you also flag tasks that will miss their due date given estimates?
- What if some tasks have no due date?
- Can you update the order incrementally when one dependency is added?
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: {task_id: due_date} with ISO date strings (which sort correctly as strings) and (blocker, blocked) pairs. Output: a valid topological order that greedily picks the earliest-due available ta...
High-Level Design
Plain Kahn's algorithm yields some valid order. Replacing its queue with a min-heap of (due, id) makes the choice at each step deterministic and deadline-aware while preserving validity, since a tas...