FastPrepMerge Two Sorted Streams with Next Calls

Merge Two Sorted Streams with Next Calls

Bloomberg LP logoBloomberg LP● EasyNEW GRADONSITE INTERVIEW
Learn

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.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int[] mergeNextValues(int[] first, int[] second, int calls) {
  // Write your code here.
}
first[1,4,7]
second[2,4,8]
calls5
expected[1,2,4,4,7]
Checking account…