FastPrepBuild the Task Hierarchy
Problems/Build the Task Hierarchy

Build the Task Hierarchy

Pendo logoPendo● EasyFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Pendo backend coding assessment for a senior software engineer role.

The report gave the three parts of the task: nest each subtask under its parent, fix each parent's completion status from its subtasks, and sort both levels by creation time. It also gave the task fields, a small sample input and the start of the expected output. It gave no limits and did not say what to do with a subtask whose parent is not in the list, a parent with no subtasks, or tasks created at the same time. Our choices: each task is a row of seven strings, the answer is returned as one JSON string, a subtask without a parent in the list is left out, a parent with no subtasks keeps its own status, a parent with subtasks is complete only when all of them are, equal times keep the input order, and there are at most 50 tasks.

Our version is about 85% the same as the reported question.

You are given a flat list of tasks. Each task is either a ParentTask or a SubTask. Each row of tasks describes one task with seven fields, in this order: [id, name, isExpanded, createdAt, updatedAt, isCompleted, parentId].

  • id: the unique identifier of the task.
  • name: the task description.
  • isExpanded: a UI state, whether the task is expanded in the UI. It is "true" or "false".
  • createdAt and updatedAt: times written as YYYY-MM-DDTHH:MM:SSZ.
  • isCompleted: the completion state, "true" or "false".
  • parentId: if it is the empty string "", the task is a ParentTask. Otherwise the task is a SubTask, and parentId is the id of its parent task.

Turn the flat list into a nested structure in three parts:

  1. Build the hierarchy. The result is an array that contains only ParentTasks at the top level. Each ParentTask has a subTasks array with all of its SubTasks nested inside. A SubTask whose parentId does not match the id of any task in tasks has no parent to go under, so it is left out.
  2. Recompute the completion status of each ParentTask. If a ParentTask has at least one SubTask, its isCompleted is true when all of its SubTasks are completed and false otherwise. A ParentTask with no SubTasks keeps its own isCompleted value.
  3. Sort the output. Sort the ParentTasks by createdAt in ascending order (oldest first), and sort the SubTasks in each subTasks array the same way. Tasks with the same createdAt keep their order from tasks.

Return the result as a JSON string with no spaces or line breaks. A ParentTask object has the keys id, name, isExpanded, createdAt, updatedAt, isCompleted, parentId and subTasks, in this order. A SubTask object has the same first seven keys and no subTasks key. isExpanded and isCompleted are written as JSON booleans (true or false, without quotes), and the other fields as JSON strings. Every value is copied from the input unchanged, except the isCompleted value of a ParentTask in part 2. A ParentTask with no SubTasks has "subTasks":[], and if there is no ParentTask the answer is "[]".

Function

buildTaskHierarchy(tasks: String[][]) → String

Examples

Example 1

tasks = [["st021","Design auth flow","false","2026-01-05T09:12:00Z","2026-01-06T10:00:00Z","true","t004"],["st004","Create Firebase project","false","2026-01-01T10:15:00Z","2026-01-02T09:00:00Z","true","t001"],["t001","Setup project auth","true","2026-01-01T09:00:00Z","2026-01-02T12:00:00Z","true",""],["st030","Seed test data","false","2026-01-06T10:10:00Z","2026-01-07T11:00:00Z","false","t006"]]return = "[{\"id\":\"t001\",\"name\":\"Setup project auth\",\"isExpanded\":true,\"createdAt\":\"2026-01-01T09:00:00Z\",\"updatedAt\":\"2026-01-02T12:00:00Z\",\"isCompleted\":true,\"parentId\":\"\",\"subTasks\":[{\"id\":\"st004\",\"name\":\"Create Firebase project\",\"isExpanded\":false,\"createdAt\":\"2026-01-01T10:15:00Z\",\"updatedAt\":\"2026-01-02T09:00:00Z\",\"isCompleted\":true,\"parentId\":\"t001\"}]}]"

Task t001 has an empty parentId, so it is the only ParentTask. st004 names t001 as its parent, so it goes into the subTasks array of t001. st021 and st030 name t004 and t006, which are not in the list, so they are left out. The only SubTask of t001 is completed, so t001 stays completed (true).

Example 2

tasks = [["t2","Write docs","false","2026-03-02T08:00:00Z","2026-03-04T09:00:00Z","true",""],["s21","Draft outline","false","2026-03-03T09:30:00Z","2026-03-03T17:00:00Z","true","t2"],["t1","Ship release","true","2026-03-01T10:00:00Z","2026-03-01T18:00:00Z","false",""],["s22","Add examples","false","2026-03-02T12:00:00Z","2026-03-02T12:00:00Z","false","t2"],["s12","Run tests","false","2026-03-01T15:45:00Z","2026-03-01T16:30:00Z","true","t1"],["s11","Freeze branch","true","2026-03-01T11:20:00Z","2026-03-01T11:25:00Z","true","t1"]]return = "[{\"id\":\"t1\",\"name\":\"Ship release\",\"isExpanded\":true,\"createdAt\":\"2026-03-01T10:00:00Z\",\"updatedAt\":\"2026-03-01T18:00:00Z\",\"isCompleted\":true,\"parentId\":\"\",\"subTasks\":[{\"id\":\"s11\",\"name\":\"Freeze branch\",\"isExpanded\":true,\"createdAt\":\"2026-03-01T11:20:00Z\",\"updatedAt\":\"2026-03-01T11:25:00Z\",\"isCompleted\":true,\"parentId\":\"t1\"},{\"id\":\"s12\",\"name\":\"Run tests\",\"isExpanded\":false,\"createdAt\":\"2026-03-01T15:45:00Z\",\"updatedAt\":\"2026-03-01T16:30:00Z\",\"isCompleted\":true,\"parentId\":\"t1\"}]},{\"id\":\"t2\",\"name\":\"Write docs\",\"isExpanded\":false,\"createdAt\":\"2026-03-02T08:00:00Z\",\"updatedAt\":\"2026-03-04T09:00:00Z\",\"isCompleted\":false,\"parentId\":\"\",\"subTasks\":[{\"id\":\"s22\",\"name\":\"Add examples\",\"isExpanded\":false,\"createdAt\":\"2026-03-02T12:00:00Z\",\"updatedAt\":\"2026-03-02T12:00:00Z\",\"isCompleted\":false,\"parentId\":\"t2\"},{\"id\":\"s21\",\"name\":\"Draft outline\",\"isExpanded\":false,\"createdAt\":\"2026-03-03T09:30:00Z\",\"updatedAt\":\"2026-03-03T17:00:00Z\",\"isCompleted\":true,\"parentId\":\"t2\"}]}]"

The ParentTasks are t1, created on March 1, and t2, created on March 2, so t1 comes first even though it is listed after t2. Under t1, s11 (11:20) comes before s12 (15:45). Both are completed, so t1 changes from false to true. Under t2, s22 (March 2) comes before s21 (March 3). s22 is not completed, so t2 changes from true to false.

Example 3

tasks = [["b","Plan sprint","false","2026-05-04T09:00:00Z","2026-05-04T09:00:00Z","true",""],["a","Review code","true","2026-05-04T09:00:00Z","2026-05-05T10:00:00Z","false",""],["a2","Check tests","false","2026-05-04T13:00:00Z","2026-05-04T15:00:00Z","true","a"],["a1","Check style","false","2026-05-04T13:00:00Z","2026-05-04T14:00:00Z","false","a"],["c","Clean backlog","false","2026-05-01T08:00:00Z","2026-05-02T08:00:00Z","false",""]]return = "[{\"id\":\"c\",\"name\":\"Clean backlog\",\"isExpanded\":false,\"createdAt\":\"2026-05-01T08:00:00Z\",\"updatedAt\":\"2026-05-02T08:00:00Z\",\"isCompleted\":false,\"parentId\":\"\",\"subTasks\":[]},{\"id\":\"b\",\"name\":\"Plan sprint\",\"isExpanded\":false,\"createdAt\":\"2026-05-04T09:00:00Z\",\"updatedAt\":\"2026-05-04T09:00:00Z\",\"isCompleted\":true,\"parentId\":\"\",\"subTasks\":[]},{\"id\":\"a\",\"name\":\"Review code\",\"isExpanded\":true,\"createdAt\":\"2026-05-04T09:00:00Z\",\"updatedAt\":\"2026-05-05T10:00:00Z\",\"isCompleted\":false,\"parentId\":\"\",\"subTasks\":[{\"id\":\"a2\",\"name\":\"Check tests\",\"isExpanded\":false,\"createdAt\":\"2026-05-04T13:00:00Z\",\"updatedAt\":\"2026-05-04T15:00:00Z\",\"isCompleted\":true,\"parentId\":\"a\"},{\"id\":\"a1\",\"name\":\"Check style\",\"isExpanded\":false,\"createdAt\":\"2026-05-04T13:00:00Z\",\"updatedAt\":\"2026-05-04T14:00:00Z\",\"isCompleted\":false,\"parentId\":\"a\"}]}]"

c is the oldest ParentTask. b and a have the same createdAt, so they keep their input order: b before a. c and b have no SubTasks, so they keep their own isCompleted values, false and true, and get an empty subTasks array. The two SubTasks of a also share a createdAt, so a2 stays before a1. a1 is not completed, so a is false.

Constraints

  • 0 <= tasks.length <= 50
  • tasks[i].length == 7
  • 0 <= tasks[i][j].length <= 30
  • Every id is unique and has 1 to 10 letters or digits.
  • name has 1 to 30 characters, and each one is a letter, a digit or a space.
  • isExpanded and isCompleted are each "true" or "false".
  • createdAt and updatedAt are valid UTC times written as YYYY-MM-DDTHH:MM:SSZ, with a year from 2000 to 2099.
  • parentId is "" or 1 to 10 letters or digits. It is never the task's own id, and it never names a SubTask, so there are only two levels.

Similar questions at other companies

  • Count User Mentions in Chat MessagesRamp · OARamp interview questions
  • Word Frequency Counts in Alphabetical OrderAbridge · OAAbridge interview questions
  • Minimum Magic Stones After MergesElevenLabs · OAElevenLabs interview questions
  • Items SortAkuna Capital · OAAkuna Capital interview questions
  • Count Cross-Array Target-Sum PairsVisa · OAVisa interview questions
  • Array Rank TransformTata Consultancy Services · OATata Consultancy Services interview questions
  • Find Max Health SumAmazon · OA
  • Influencers SquadTikTok · OATikTok interview questions
  • Count Teams Outscoring a Target TeamBloomberg LP · OABloomberg LP interview questions
  • Count Soldiers with a Next-Rank SuperiorMarshall Wace · OAMarshall Wace interview questions
See Pendo hiring insights
Saved
class Solution {
    public String buildTaskHierarchy(String[][] tasks) {
        // Write your code here.
    }
}

Not a valid String

Checking account…