A pixel-art editor saves each row of the canvas compactly. A row is a list of color names, and long stretches of one color are common.
Write compressRow(colors) that returns a list of [color, count] pairs, one for each run of equal neighboring colors, in order. An empty row gives an empty list.
Input: colors = ["white","white","white","red","white","white"] Output: [["white",3],["red",1],["white",2]]
Three runs: three white, one red, two white.
Input: colors = ["blue"] Output: [["blue",1]]
One pixel is one run of length 1.
0 <= colors.length <= 10^5Run 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 #622 Compress a Pixel Row. 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.