Exercise · Final project · lesson 5 of 7
Exercise: merge sorted slices
Write a function func mergeSorted(a, b []int) []int that merges two slices sorted in ascending order into a new slice, also sorted in ascending order. The result holds every number from a and b, duplicates included.
mergeSorted([]int{1, 4, 6}, []int{2, 3, 7})→[1 2 3 4 6 7]mergeSorted([]int{1, 3, 3}, []int{3, 4})→[1 3 3 3 4]mergeSorted([]int{}, []int{2, 9})→[2 9]
Constraints: each slice holds from 0 to 1000 numbers, which can include negative numbers and repeats; either slice can be empty, and for two empty slices the function returns an empty slice.
Do not add extra imports unless the task says so explicitly.
Subscribe to take the course
The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.