Challenge - 5 Problems
Quick Sort Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Quick Sort Partition Step
What is the output of the array after the partition step in Quick Sort using the last element as pivot?
DSA Go
func partition(arr []int, low, high int) int { pivot := arr[high] i := low - 1 for j := low; j < high; j++ { if arr[j] < pivot { i++ arr[i], arr[j] = arr[j], arr[i] } } arr[i+1], arr[high] = arr[high], arr[i+1] return i + 1 } arr := []int{10, 7, 8, 9, 1, 5} pi := partition(arr, 0, len(arr)-1) fmt.Println(arr)
Attempts:
2 left
💡 Hint
Focus on how elements smaller than the pivot are moved before it.
✗ Incorrect
The partition function moves all elements smaller than the pivot (last element) to the left and places the pivot after them. The array after partitioning is [1 5 7 8 9 10].
🧠 Conceptual
intermediate1:00remaining
Quick Sort Average Time Complexity
What is the average time complexity of the Quick Sort algorithm?
Attempts:
2 left
💡 Hint
Think about how the array is divided and conquered.
✗ Incorrect
Quick Sort on average divides the array into two halves and sorts recursively, leading to O(n log n) time complexity.
❓ Predict Output
advanced2:00remaining
Final Sorted Array After Quick Sort
What is the final sorted array after applying Quick Sort on the given array?
DSA Go
func quickSort(arr []int, low, high int) { if low < high { pi := partition(arr, low, high) quickSort(arr, low, pi-1) quickSort(arr, pi+1, high) } } func partition(arr []int, low, high int) int { pivot := arr[high] i := low - 1 for j := low; j < high; j++ { if arr[j] < pivot { i++ arr[i], arr[j] = arr[j], arr[i] } } arr[i+1], arr[high] = arr[high], arr[i+1] return i + 1 } arr := []int{4, 2, 6, 9, 3} quickSort(arr, 0, len(arr)-1) fmt.Println(arr)
Attempts:
2 left
💡 Hint
Quick Sort sorts the array in ascending order.
✗ Incorrect
Quick Sort sorts the array fully in ascending order, so the final output is [2 3 4 6 9].
🔧 Debug
advanced2:00remaining
Identify the Bug in Quick Sort Partition
What error will this Quick Sort partition code cause when run?
DSA Go
func partition(arr []int, low, high int) int { pivot := arr[high] i := low for j := low; j < high; j++ { if arr[j] <= pivot { arr[i], arr[j] = arr[j], arr[i] i++ } } arr[i], arr[high] = arr[high], arr[i] return i }
Attempts:
2 left
💡 Hint
Check how the initial value of i affects the partitioning.
✗ Incorrect
The initial value of i should be low - 1, not low. Starting at low causes incorrect partition index and wrong sorting.
🚀 Application
expert1:30remaining
Quick Sort Stability Check
Given the array of structs [{value: 3, id: 'a'}, {value: 3, id: 'b'}, {value: 1, id: 'c'}], which statement about Quick Sort is true?
Attempts:
2 left
💡 Hint
Think about how Quick Sort swaps elements during partition.
✗ Incorrect
Quick Sort is not stable because it swaps elements that may change the relative order of equal elements.