Foundations · lesson 2 · ~12 min

Constraints are
the answer key.

Problem setters choose the limits so the intended solution passes and the naive one times out. Read the constraints before the story, multiply by the budget, and you know the target complexity before writing a line. Often you also learn which technique to reach for.

4labs
0drills + endless lightning
0your lightning best
read-constraints.sh
01

The budget: about 10⁸ simple steps a second

A judge gives you roughly 1–2 seconds, and a typical machine does about 10⁸ simple operations per second. Divide that budget by your algorithm's cost and you get the largest n each complexity can survive. Drag across the bars to move n.

How far each class gets

solid = fits · amber = borderline (≤5× budget) · striped = TLE
n ≤
time limit
machine
language
work / step
×1
02

Constraint decoder

Paste the constraints block from any problem, or pick an example, and read it the way a strong candidate does: sizes, value ranges, then the small words. Edit the numbers and watch the reading change.

Try:

Constraints

one per line · ≤, <=, 10^5, 10⁵, 2 * 10^5, 1e5 all work
The habit: before reading the story, scroll to the constraints and say the target complexity out loud. Interviewers notice when you do it.

The reading

03

Clue words: the constraints that aren't numbers

Some lines don't change the budget. They tell you which tool to use. Tap a card for an example.

04

Many variables: multiply before you judge

Grids, queries, graphs and test cases give you two numbers. The cost depends on how they combine: m·n cells, n·q work, V + E edges. Move both sliders and see which approaches survive.

05

Constraint Gym

Pick the target: read real-looking constraints and choose the slowest approach that still passes. Pass or TLE?: 60 seconds, one n and one complexity at a time. Decide fast. Keys: 1–4 for options, ← pass and → TLE, Enter for next.

0in a row
–accuracy
0/0drills cleared
0lightning best