Skip to the code
cf.
+25 XP

#221 Sort the Task Board

medium

A project board lists tasks as objects { title, priority, due }. priority is "high", "medium", or "low", and due is a day number. The board shows high-priority tasks first, then medium, then low. Within a priority, earlier due days come first. If those match too, titles go in dictionary order by character codes.

Write sortBoard(tasks) that returns the task titles in board order. Do not change the input.

Example 1

Input: tasks = [{"title":"Docs","priority":"low","due":1},{"title":"Login bug","priority":"high","due":5},{"title":"Navbar","priority":"high","due":2}]
Output: ["Navbar","Login bug","Docs"]

Both high tasks come first, the one due on day 2 before day 5. The low task goes last even though it is due soonest.

Example 2

Input: tasks = [{"title":"b","priority":"medium","due":3},{"title":"a","priority":"medium","due":3}]
Output: ["a","b"]

Same priority and day, so the titles decide.

Constraints

  • 0 <= tasks.length <= 10000
  • Titles are distinct non-empty strings.
  • 0 <= due <= 10^6
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).