Complete the code to perform a comparison-based sort using Go's built-in function.
import "sort" func sortNumbers(nums []int) { sort.[1](nums) }
The correct function to sort a slice of ints in Go is sort.Ints.
Complete the code to implement counting sort, a non-comparison based sorting algorithm.
func countingSort(arr []int, maxVal int) []int {
count := make([]int, maxVal+1)
for _, num := range arr {
count[[1]]++
}
// rest of the code omitted
return nil
}We increment the count for each number in the input array, so num is the correct index.
Fix the error in the code that attempts to compare two integers for sorting.
func compare(a, b int) bool {
return a [1] b
}For sorting in descending order, the comparison should be a > b.
Fill both blanks to complete the code that builds a frequency map for radix sort.
func buildFrequency(arr []int, digit int) map[int]int {
freq := make(map[int]int)
for _, num := range arr {
d := (num / [1]) % [2]
freq[d]++
}
return freq
}To extract the digit at a certain place, divide by digit and mod by 10.
Complete the code to complete the code that creates a map of word lengths filtered by length condition.
func filterWords(words []string) map[int]int {
result := make(map[int]int)
for _, word := range words {
if len(word) [1] 3 {
result[[len(word)]]++
}
}
return result
}The condition filters lengths greater than 3, and the map key uses brackets to index the length for frequency count.