Skip to main content

Time Complexity · #30 · 2026-05-04

What's the Big-O?

Python ·Difficulty 2/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 time complexity?

def three_sum(arr):
    arr.sort()
    result = []
    for i in range(len(arr) - 2):
        lo, hi = i + 1, len(arr) - 1
        while lo < hi:
            s = arr[i] + arr[lo] + arr[hi]
            if s == 0:
                result.append((arr[i], arr[lo], arr[hi]))
                lo += 1
                hi -= 1
            elif s < 0:
                lo += 1
            else:
                hi -= 1
    return result

Loading your progress...

Press 1 through 4, or tap a numbered choice, to answer. Back to hub