Time Complexity · #14 · 2026-04-18
What's the Big-O?
Python ·Difficulty 3/3
How to play
Read the code and pick its time complexity from four Big-O choices. Think about loops, recursion, and hidden costs. Press 1–4 or click to answer.
n = len(arr). What is the average-case time complexity?
def quickselect(arr, k):
pivot = arr[len(arr) // 2]
left = [x for x in arr if x < pivot]
mid = [x for x in arr if x == pivot]
right = [x for x in arr if x > pivot]
if k < len(left):
return quickselect(left, k)
elif k < len(left) + len(mid):
return mid[0]
else:
return quickselect(right, k - len(left) - len(mid))
Loading your progress...
Press 1 through 4, or tap a numbered choice, to answer. Back to hub