Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to perform a stable sort on the slice of integers.
DSA Go
sort.SliceStable(numbers, func(i, j int) bool { return numbers[i] [1] numbers[j] }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' causes descending order, which is not the intended stable ascending sort.
Using '==' does not define a strict ordering and causes runtime errors.
✗ Incorrect
Using '<' in the comparison function ensures the sort is ascending and stable.
2fill in blank
mediumComplete the code to perform an unstable sort on the slice of integers.
DSA Go
sort.Slice(numbers, func(i, j int) bool { return numbers[i] [1] numbers[j] }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' can cause unexpected behavior in unstable sorts.
Using '==' is invalid for sorting comparison.
✗ Incorrect
Using '<' in the comparison function performs an unstable ascending sort.
3fill in blank
hardFix the error in the comparison function to ensure a stable sort by age in ascending order.
DSA Go
sort.SliceStable(people, func(i, j int) bool { return people[i].Age [1] people[j].Age }) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' sorts in descending order, which is not the requirement.
Using '==' does not define a strict order and causes errors.
✗ Incorrect
Using '<' correctly sorts people by ascending age while preserving stability.
4fill in blank
hardFill both blanks to create a map of names to ages for people older than 30.
DSA Go
result := map[string]int{person.Name: person.[1] for _, person := range people if person.Age [2] 30} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Name' instead of 'Age' for the map value.
Using '<=' instead of '>' in the condition.
✗ Incorrect
Use 'Age' to get the age value and '>' to filter people older than 30.
5fill in blank
hardFill all four blanks to create a filtered map of uppercase names to ages for people younger than 25.
DSA Go
result := map[string]int{strings.[1](person.[2]): person.[3] for _, person := range people if person.Age [4] 25} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'ToLower' instead of 'ToUpper'.
Using '>' instead of '<' in the condition.
✗ Incorrect
Use 'ToUpper' to uppercase names, 'Name' for the key, 'Age' for the value, and '<' to filter younger than 25.