Merge Two Sorted Streams with Next Calls
Problem statement
first and second are nondecreasing finite streams. A stateful next() returns the smaller current head, advancing that stream; equal values are both preserved, with first chosen before second on a tie.
Return the first calls values produced.
Function
mergeNextValues(first: int[], second: int[], calls: int) → int[]Examples
Example 1
first = [1,4,7]second = [2,4,8]calls = 5return = [1,2,4,4,7]Five next calls preserve both copies of 4.
Constraints
0 <= calls <= first.length + second.length.