A memory-tight table component keeps its row ids in a buffer rows. The first count items are real ids sorted ascending; the rest of the buffer is reserved space filled with 0s, exactly incoming.length of them. New ids arrive in incoming, also sorted ascending.
Write mergeInto(rows, count, incoming) that merges incoming into rows in place so the whole buffer is sorted ascending. Don't create another array. The tests check rows after your function runs.
Input: rows = [2,5,9,0,0], count = 3, incoming = [1,6] Output: [1,2,5,6,9]
The two reserved spots take the new ids, and everything ends sorted.
Input: rows = [0,0], count = 0, incoming = [3,4] Output: [3,4]
There were no rows yet.
rows.length === count + incoming.length0 <= count, incoming.length <= 100000-10^9 <= ids <= 10^9Run 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 #112 Merge Into the Reserved Tail. 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.