Challenge - 5 Problems
Sorting Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of Merging Two Sorted Lists
What is the printed output after merging these two sorted lists using the given code?
DSA Python
def merge_sorted_lists(a, b): result = [] i = j = 0 while i < len(a) and j < len(b): if a[i] < b[j]: result.append(a[i]) i += 1 else: result.append(b[j]) j += 1 result.extend(a[i:]) result.extend(b[j:]) print(result) merge_sorted_lists([1, 3, 5], [2, 4, 6])
Attempts:
2 left
💡 Hint
Think about how two sorted lists combine to keep order.
✗ Incorrect
The function merges two sorted lists by comparing elements one by one and appending the smaller element, resulting in a fully sorted merged list.
🧠 Conceptual
intermediateWhy Sorting Helps in Searching
Why does sorting a list help algorithms like binary search work efficiently?
Attempts:
2 left
💡 Hint
Think about how binary search divides the list.
✗ Incorrect
Binary search requires a sorted list to decide which half to discard at each step, making search faster than checking every element.
❓ Predict Output
advancedOutput of Sorting and Removing Duplicates
What is the output of the following code that sorts a list and removes duplicates?
DSA Python
data = [4, 2, 5, 2, 3, 4, 1] unique_sorted = sorted(set(data)) print(unique_sorted)
Attempts:
2 left
💡 Hint
Remember that set removes duplicates and sorted arranges elements.
✗ Incorrect
The set removes duplicates, and sorted arranges the unique elements in ascending order.
🔧 Debug
advancedIdentify the Error in Sorting Code
What error does this code raise when trying to sort a list of mixed types?
DSA Python
items = [3, 'apple', 1, 'banana'] items.sort() print(items)
Attempts:
2 left
💡 Hint
Think about comparing numbers and words.
✗ Incorrect
Python cannot compare integers and strings directly during sorting, causing a TypeError.
🚀 Application
expertUsing Sorting to Find the Median
Given an unsorted list of numbers, which code correctly finds the median value?
Attempts:
2 left
💡 Hint
Median is the middle value after sorting.
✗ Incorrect
Sorting the list and picking the middle element gives the median for an odd-length list.
