Complete the code to choose the pivot element as the last element of the slice.
pivot := arr[[1]]The pivot is chosen as the last element of the slice, which is at index len(arr) - 1.
Complete the code to swap elements at indices i and j in the slice.
arr[[1]], arr[j] = arr[j], arr[[1]]
j for both sides causes no change.To swap elements at indices i and j, use arr[i], arr[j] = arr[j], arr[i].
Fix the error in the partition function to correctly increment the index i.
if arr[j] < pivot { i[1] arr[i], arr[j] = arr[j], arr[i] }
In Go, to increment i by 1, use i += 1. The ++ operator is a statement, not an expression, so it cannot be used inside another statement.
Fill both blanks to complete the recursive quicksort calls on sub-slices.
quickSort(arr[:[1]]) quickSort(arr[[2]:])
The left sub-slice is from start to pivotIndex - 1, and the right sub-slice is from pivotIndex + 1 to the end.
Fill all three blanks to define the partition function signature and return statement.
func partition(arr []int) [1] { pivot := arr[len(arr)-1] i := -1 for j := 0; j < len(arr)-1; j++ { if arr[j] < pivot { i[2] arr[i], arr[j] = arr[j], arr[i] } } arr[i+1], arr[len(arr)-1] = arr[len(arr)-1], arr[i+1] return [3] }
The partition function returns an int index. Increment i by 1 using i += 1. Return i + 1 as the pivot's final position.
