A status board shows one light per service: 0 for red (down), 1 for yellow (degraded), and 2 for green (healthy). The board should list all red lights first, then yellow, then green.
Write sortLights(lights) that sorts lights in place in one pass, using O(1) extra memory and without calling sort. The tests check lights after your function runs.
Input: lights = [2,0,1,2,0] Output: [0,0,1,2,2]
Reds, then yellows, then greens.
Input: lights = [1,1,1] Output: [1,1,1]
Only yellow lights, so nothing moves.
0 <= lights.length <= 1000000, 1, or 2.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).
I'm here to help with #120 Sort Traffic Light States. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.