Process a Task List: Deduplicate, Drop Completed, Sort by Priority, and Nest Subtasks
Company: Rippling
Role: Backend Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Onsite
You are given a batch of tasks for a task scheduler. Each task has a description, a due date, a priority, a completed flag, and an optional parent id that links a subtask to its parent task. Produce the list of tasks to display:
1. Remove duplicates, where two tasks are duplicates if they have the same `(description, due_date)`.
2. Drop tasks that are already completed.
3. Sort the remaining tasks by the priority rule the interviewer provides.
4. Place every subtask immediately after its parent.
Assume, as implied context, that each task also has a unique `id` that `parent_id` refers to:
```python
from dataclasses import dataclass
from datetime import date
from typing import Optional
@dataclass
class Task:
id: int
description: str
due_date: date
priority: int
completed: bool
parent_id: Optional[int] # None for a top-level task
def build_schedule(tasks: list[Task]) -> list[Task]:
...
```
### Constraints and Clarifications
- The coding environment includes an AI assistant. You are expected to use it the way you would at work, while making the decisions yourself and explaining them as you go.
- The steps are listed in the order the prompt gives them; if the order changes the result for some input, point that out.
- The exact priority rule is part of the prompt the interviewer supplies; ask for it rather than guessing.
### Clarifying Questions
- What is the priority rule: is a larger or smaller value more urgent, and how are ties broken (due date, description, id)?
- When two tasks are duplicates, which one is kept, especially if one is completed and the other is not, or they have different parents or priorities?
- If a removed duplicate had subtasks, should those subtasks attach to the task that was kept?
- What happens to a subtask whose parent was dropped because it was completed, or whose `parent_id` does not exist?
- Can subtasks have their own subtasks, and should siblings be ordered by the same priority rule?
- Can the input contain a parent cycle, and if so, is that an error?
### Part 1 — Implement the Schedule Builder
Implement `build_schedule` so it returns the tasks in display order.
```hint Order first, then place children
Consider sorting all surviving tasks once, then building the output by visiting top-level tasks in that order and emitting each task's children right after it.
```
```hint Remap before you nest
If a duplicate is removed, think about what should happen to any task whose parent_id pointed at the removed copy.
```
#### What This Part Should Cover
- Deduplication on the exact key with a stated rule for which copy survives and how references to removed copies are redirected.
- Filtering and a sort that implements the agreed priority rule with a deterministic tie-break.
- A traversal that places each subtask directly after its parent at any depth, with defined handling for orphans and cycles, and its complexity.
### Part 2 — Working With the AI Assistant
Describe how you would use the provided assistant during this exercise: what you would ask it to do, what you would decide yourself, and how you would check its output.
```hint Delegate the checkable parts
Think about which pieces of this problem have an unambiguous correct result you can verify quickly, and which pieces are policy decisions that depend on the clarifying questions.
```
#### What This Part Should Cover
- A split between delegated mechanical work and decisions the candidate owns.
- How the candidate verifies generated code against the agreed rules, including edge-case tests.
- Narrating reasoning so the interviewer can follow the collaboration.
### What a Strong Answer Covers
- Clarifying questions asked up front, with the unresolved policies decided explicitly rather than left to whatever the code happens to do.
- A correct pipeline in the right order, with deterministic output for ties and duplicates.
- Correct nesting at arbitrary depth, plus handling for orphaned subtasks, dangling parent ids, and cycles.
- $O(n \log n)$ complexity with a clear explanation.
- Effective, verified use of the AI assistant, with the candidate clearly in control of design decisions.
### Follow-up Questions
1. If a completed parent still has incomplete subtasks, what would you show the user, and how would your code change?
2. How would you test this function, and which cases would you write first?
3. If tasks arrive continuously rather than in a batch, how would you maintain the display order incrementally?
Overview: Senior backend coding question: process a batch of scheduler tasks by removing duplicates on description and due date, dropping completed tasks, sorting by priority, and placing each subtask directly after its parent. It tests clarifying ambiguous policies, orphan and cycle handling, O(n log n) design, and verified use of an AI coding assistant.
Read the full Rippling Backend Engineer interview experience this question came from