Example 1 · empty
- Arguments
- a
[]
b[]
- Expected return
[]
Test data
- Input
{"a":[],"b":[]}- Expected output
[]
func MergeSorted(a, b []int) []intExamples use {"a": [...], "b": [...]}.
The runner calls your functions directly; you do not need to parse JSON.
[]
[]
[]
{"a":[],"b":[]}[]
[ 1, 4, 8 ]
[ 2, 3, 9 ]
[ 1, 2, 3, 4, 8, 9 ]
{"a":[1,4,8],"b":[2,3,9]}[1,2,3,4,8,9]
[ 1, 1, 3 ]
[ 1, 2, 3 ]
[ 1, 1, 1, 2, 3, 3 ]
{"a":[1,1,3],"b":[1,2,3]}[1,1,1,2,3,3]
[]
[ -3, 0, 2 ]
[ -3, 0, 2 ]
{"a":[],"b":[-3,0,2]}[-3,0,2]
Each cursor points to the smallest unconsumed value in its input. The smaller of those two values is therefore the smallest remaining value overall. Appending it preserves sorted output, and consuming each input position once preserves every duplicate count.
O(a + b) time for input lengths a and b, with O(1) auxiliary space excluding the O(a + b) returned output. Both cursors move forward at most their input length.
Checking execution availability…
View inputs and expected outputs. Examples do not run your code.