Skip to the code
cf.
+10 XP

#121 Order Tickets by Severity

easy

A support inbox labels each ticket with a severity: "high", "medium", or "low". The triage view must show every "high" ticket first, then "medium", then "low".

Write orderBySeverity(tickets) that rearranges the array of labels in place in one pass, with O(1) extra memory and without calling sort. The tests check tickets after your function runs.

Example 1

Input: tickets = ["low","high","medium","high"]
Output: ["high","high","medium","low"]

Both high tickets come first, then medium, then low.

Example 2

Input: tickets = ["medium","low"]
Output: ["medium","low"]

Already in order.

Constraints

  • 0 <= tickets.length <= 100000
  • Each item is "high", "medium", or "low".
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).