Challenge - 5 Problems
Sorting Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of Sorted Slice After Using Built-in Sort
What is the output of the following Go code that sorts a slice of integers?
DSA Go
package main import ( "fmt" "sort" ) func main() { nums := []int{5, 3, 8, 1, 2} sort.Ints(nums) fmt.Println(nums) }
Attempts:
2 left
💡 Hint
Think about what sort.Ints does to the slice.
✗ Incorrect
The sort.Ints function sorts the slice in ascending order, so the output is the sorted slice.
🧠 Conceptual
intermediate1:30remaining
Why Sorting Helps in Searching Algorithms
Why is sorting a list important before applying binary search?
Attempts:
2 left
💡 Hint
Think about how binary search splits the list.
✗ Incorrect
Binary search divides the list into halves based on order, so the list must be sorted for it to work correctly.
🔧 Debug
advanced2:30remaining
Identify the Output or Error in Custom Sorting
What will be the output or error of this Go code that tries to sort a slice of strings by length?
DSA Go
package main import ( "fmt" "sort" ) type ByLength []string func (s ByLength) Len() int { return len(s) } func (s ByLength) Swap(i, j int) { s[i], s[j] = s[j], s[i] } func (s ByLength) Less(i, j int) bool { return len(s[i]) < len(s[j]) } func main() { fruits := []string{"pear", "apple", "banana", "kiwi"} sort.Sort(ByLength(fruits)) fmt.Println(fruits) }
Attempts:
2 left
💡 Hint
Check how the Less function compares string lengths.
✗ Incorrect
The code sorts the slice by string length ascending, so shortest strings come first.
🚀 Application
advanced2:00remaining
Using Sorting to Find the Median
Given an unsorted slice of integers, which step is necessary to find the median value correctly?
Attempts:
2 left
💡 Hint
Median depends on order, so what must you do first?
✗ Incorrect
Median is the middle value in sorted order, so sorting is required before selecting it.
🧠 Conceptual
expert3:00remaining
Why Sorting Unlocks Efficient Algorithms Like Two-Pointer Technique
How does sorting a list enable the two-pointer technique to find pairs with a specific sum efficiently?
Attempts:
2 left
💡 Hint
Think about how sorted order helps decide pointer movement.
✗ Incorrect
With a sorted list, two pointers can start at ends and move inward, skipping unnecessary checks, making the search efficient.