Opening your workspace…
Workspace/Coding room
Opening your workspace…
Two brewery branches list their spare crates by roast-day number in nondecreasing order. A tasting exchange pairs one crate from each branch only when their roast-day numbers match. Each crate can be used once. Return the roast-day numbers of as many pairs as possible, in nondecreasing order. Repeated numbers represent different crates, so include a number once for every pair it can make. Do not rearrange or modify either input list.
[2,2,5,9], [2,5,5,9]Output[2,5,9]One crate of day 2, one of day 5, and one of day 9 can be paired. The extra day-2 crate has no partner.
[4,4,4], [4,4]Output[4,4]Two distinct day-4 pairs use both crates from the second branch.
Keep one pointer in each sorted list. If the current numbers differ, can the smaller one match anything still ahead in the other list?
/** @param {number[]} north * @param {number[]} south * @returns {number[]} */ function solve(north, south) { // Match crates without changing either sorted list. }
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.
[2,2,5,9], [2,5,5,9][2,5,9]