Task Management
At the very start I was asked to choose between AI assist and no AI assist (I chose no AI assist).
Part 1:
addTask
printTasks
printTasks has filter and sort logic that you need to handle.
From what I remember, the Task properties were:
- int id
- String description
- int dueDate
- boolean isPriorityTask
- int createdDate
- String assignee (I forget whether it was String or int)
- int status (I forget whether it was int or boolean; it is used to identify whether the task is done or not)
- int parentTaskId
Filter logic: the task has no assignee and its status is not done.
Sort logic:
- the task with the smaller due date gets printed first (but -1 means no due date, so those go last)
- tasks with isPriorityTask == true get printed first
- the task with the smaller createdDate gets printed first (the problem description never has -1 here, but I think this was meant to be one of the things they are testing, more on that below)
Printing has a format, something like this:
If the task has no parent task, print "{taskId}: {taskDescription}".
If the task has a parent task, print "{taskId}: {taskDescription}: {parentTaskId}: {parentTaskDescription}".
Part 1 itself is implementing an add task that handles duplication, plus a print task that implements the filter and the sort logic.
For the sort part, it is best to implement a TaskComparator (implements Comparator, override the compare method) right at the start, so the later parts can reuse it.
Reading the question description for the filter and sort parts takes some time, so when you implement, be as fast as you can.
After you finish implementing, they give you a test case. Once you run it, you should proactively add edge cases.
Besides null, empty and duplication, the edge cases here may also include invalid input, for example tasks that violate the question description. For example: id <= 0, how to handle a description with leading or trailing spaces, what to do with due date < -1, what to do with createdDate <= 0, what to do if the parent task itself was never added with addTask, and so on. Basically, for every input you should assume there could be bad input and think about how to handle it.
I suggest adding a validateTask method inside addTask that handles all of these invalid task inputs in one place, and communicating how you are handling them.
Part 2:
The Task gets a new property, a List of childTaskIds. When printing, the task filter and order stay the same.
When printing a task, the format now also has to include the child tasks, with the same filter and sort logic applied to them.
So it is best to implement the TaskComparator right from the start.
I did not have time to get to part 3. My guess is that it would be a topological sort follow-up to find an execution path.
Takeaways: the problem is very simple but reading it takes time. The interviewer mentioned that the problem says add task might get duplicates and that I should handle duplicates as the problem requires. I went back and read the problem again and used ctrl + f to quickly confirm that the problem says nothing about it. The interviewer then kept telling me that it should be in there (but it really is not), so I told him it was fine and I would just use a HashMap implementation for the duplicate logic. That cost me some time. (Only at the very end did the interviewer say that the requirement would only be in the problem if you had picked AI assist.) So my advice is to wrap all of the invalid input logic in a validateTask method, and if you sense that the interviewer is deliberately being vague about the problem and keeps changing it, just write down your assumptions clearly in a comment and implement, otherwise all your time goes into clarification.
Hope these details and takeaways help everyone!
Wishing everyone in this tough time an early landing, and good luck to everyone who is on the interview road!
Update (2026-11-10): the Task was a record, not a class. If you are not familiar with records, get familiar with them.
Discussion
Loading comments…