A photo grid stores its tiles as numbers in tiles, where 0 is an empty slot. Before rendering, all real tiles should move to the front in their current order, and all empty slots should move to the end.
Write sinkEmpty(tiles) that does this in place, without creating a second array. The tests check tiles after your function runs.
Input: tiles = [0,5,0,3,8] Output: [5,3,8,0,0]
5, 3, 8 keep their order and the two empty slots move to the end.
Input: tiles = [1,2,3] Output: [1,2,3]
There are no empty slots.
0 <= tiles.length <= 100000-10^6 <= tiles[i] <= 10^6Run 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 #107 Sink Empty Grid Slots. 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.