Junior — Senior
Merging two sorted slices
livecode
Task condition
It is necessary to implement the function mergeSorted(a, b []int) []int, which:
- takes two slices of integers, already sorted in ascending order;
- forms and returns a new slice containing elements of both input slices in a single ascending order.
import "fmt"
func main() {
var first = []int{1, 5, 6, 18, 99}
var second = []int{2, 4, 9, 11}
fmt.Println(mergeSorted(first, second))
}
func mergeSorted(first []int, second []int) []int {
// implementation of the task
}