Opening your workspace…
Workspace/Coding room
Opening your workspace…
Two baristas turn up at the serving hatch with two strings of order slips, a and b. Each string is already in order from smallest number to largest. Thread all the slips onto one string and return their numbers as a single array in nondecreasing order. Keep every slip, including duplicates. Two number sevens still expect two cups of coffee. Either string may arrive bare.
[1,4,9], [2,4,8]Output[1,2,4,4,8,9]At each step, compare the front of the two queues and take the smaller order.
[], [3,7]Output[3,7]The first queue is empty, so the answer is the second queue as it stands.
You only need to compare the next unused number in each queue. Take the smaller one and move that queue's pointer forward.
/** @param {number[]} a * @param {number[]} b * @returns {number[]} */ function solve(a, b) { // Bring the two sorted queues together. }
Tab inserts two spaces. Shift+Tab outdents. Use the arrow keys and Tab to choose a suggestion. Press Escape, then Tab, to leave the editor. Press Control or Command with apostrophe to run samples or with Enter to submit.
[1,4,9], [2,4,8][1,2,4,4,8,9]