Skip to the workspace
Pebellslearn by building
Thinking in Patterns  ›  Lesson

What a Practice Problem Really Tests

What is LeetCode 12 minA coding problem is judged by hidden tests under a time limit, so its input limits tell you how fast your solution must be and which edge cases to test.

leetcode / What a Practice Problem Really Tests

Explore each scene at your own pace.

01 · The rule

The rule

What a Practice Problem Really Tests

Practice sites such as LeetCode hand you a short story, two or three examples, a list of limits and an empty function. You press Submit, and a judge runs your code against dozens of tests you never see, under a time limit. Passing the examples on the page is where the work starts, not where it ends.

The rule

The limits set your speed; the hidden tests hunt your edges.

Every problem has four parts, and beginners read only the first two:

  • The story says what to compute.
  • The examples show a few inputs and outputs.
  • The limits say how big and how strange the input can get: "1 ≤ n ≤ 100,000", "values may be negative".
  • The signature fixes the function name, inputs and return type.

The limits are the most useful line on the page. A judge usually allows about a second, and plain Python manages very roughly ten million simple steps in that time. So the largest n tells you which growth rate you can afford:

Largest input Affordable work What usually fits
about 20 2ⁿ trying every subset
about 1,000 n² a loop inside a loop
about 100,000 n log n or n sorting, one pass, a dictionary
a single value up to a billion log of the value binary search on the value

The hidden tests, meanwhile, are written to find the inputs you forgot: nothing at all, one item, ties, negatives, the largest size. A solution that is right "most of the time" is marked wrong.

def busiest_day(steps):
    best_day = 0
    for day in range(1, len(steps)):
        if steps[day] > steps[best_day]:   # strictly greater: earliest day wins a tie
            best_day = day
    return best_day
Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.