Skip to the code
cf.
+10 XP

#203 Group Tasks by Priority Level

easy

A task list gives each task a priority level from 0 (most urgent) to 4. tasks holds pairs [name, level] in the order they were created.

Write byPriority(tasks) that returns the task names ordered by level, most urgent first. Tasks with the same level must stay in the order they were created.

Example 1

Input: tasks = [["deploy",1],["fix login",0],["write docs",3],["review",1]]
Output: ["fix login","deploy","review","write docs"]

Level 0 first, then the two level 1 tasks in their original order, then level 3.

Example 2

Input: tasks = [["a",2],["b",2]]
Output: ["a","b"]

Same level: keep the original order.

Constraints

  • 0 <= tasks.length <= 100000
  • 0 <= level <= 4
  • Names are non-empty strings.
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).