Skip to the code
cf.
+25 XP

#122 Sort Four Status Levels

medium

A deploy pipeline view tags each job with a level from 0 to 3: 0 failed, 1 running, 2 queued, 3 passed. The view lists jobs from level 0 up to level 3.

Write sortLevels(levels) that sorts levels in place with O(1) extra memory, without calling sort and without counting how many of each level there are. The tests check levels after your function runs.

Example 1

Input: levels = [3,1,0,2,3,0]
Output: [0,0,1,2,3,3]

Failed jobs first, then running, queued, and passed.

Example 2

Input: levels = [2,1]
Output: [1,2]

Two middle levels swap.

Constraints

  • 0 <= levels.length <= 100000
  • Each item is 0, 1, 2, or 3.
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).