Your concept feed

21 ideas

A few small steps. No rush.

Follow the connections in this topic

Let’s picture it

Huge coordinates may have few distinct values.

10
30
1,000,000

Points lie at 10, 1,000,000, and 30. An array with a million cells wastes space.

Swipe when you’re ready
One little change

Sort unique coordinates.

10→0
30→1
1M→2

Map 10→0, 30→1, and 1,000,000→2. Comparisons preserve their original order.

Same idea. One more small step.
Now it has a name

Ranks are not distances.

rank order ✓
distance ×

Compressed difference 2−0 does not mean the original points are two units apart. Keep original gaps when geometry or length matters.

Want to try a tiny question?
No pressure. Just try it.

What does coordinate compression preserve?

You can also keep scrolling
1 / 4
Range queries

One small step at a time.

This idea builds on these smaller ones. Pick any to revisit it here.

Order can expose structure.

4
1
3
1

Unsorted values [4,1,3,1] hide equal neighbors and make smallest-first processing awkward.

1 / 3
Let’s picture it

A prefix array becomes stale after an update.

2
1→5
3
4

Values [2,1,3,4] answer sums quickly, but changing position 1 requires fixing every later stored prefix.

Swipe when you’re ready
One little change

Store sums of power-of-two blocks.

1
2-wide
1
4-wide

Each Fenwick position owns a block ending there. Binary low bits tell which blocks include an update.

Same idea. One more small step.
Now it has a name

A prefix query peels blocks backward.

index
index − lowbit
0

Add the block ending at right, clear its lowest set bit, and repeat until reaching zero.

Want to try a tiny question?
No pressure. Just try it.

Can ordinary prefix sums handle many updates in O(1) each?

You can also keep scrolling
1 / 4
Range queries

One small step at a time.

This idea builds on these smaller ones. Pick any to revisit it here.

A window meets a negative number.

2
−1
1

Find stretches totaling 2 in [2, −1, 1]. Adding −1 shrinks the sum, so the usual window direction is no longer reliable.

1 / 5
Let’s picture it

A range splits into useful pieces.

2..3
4..5
6

To sum positions 2..6, combine a few tree nodes whose intervals exactly cover that range.

Swipe when you’re ready
One little change

Parents summarize children.

left summary
right summary
parent

A sum node stores left sum plus right sum. After one leaf changes, recompute only its ancestors.

Same idea. One more small step.
Now it has a name

The combine rule defines the tree.

associative combine
identity

Sum, minimum, maximum, or gcd work when summaries combine associatively with a neutral value.

Want to try a tiny question?
No pressure. Just try it.

Why must the combine operation be associative?

You can also keep scrolling
1 / 4
Range queries

One small step at a time.

This idea builds on these smaller ones. Pick any to revisit it here.

Count a tiny family of dots.

Parent
Child: 1
Child: 1

One parent has two children. Each child says, “There’s one of me.”

1 / 3
Let’s picture it

The values never change.

1
2
4
8

For many minimum queries on one frozen array, precompute answers for blocks of lengths 1,2,4,8.

Swipe when you’re ready
One little change

Two blocks can cover a query.

left block
overlap
right block

A length-6 interval contains two length-4 blocks from its ends. They may overlap.

Same idea. One more small step.
Now it has a name

Minimum tolerates overlap.

min overlap ✓
sum overlap ×

min(x,x)=x, so double-covered values do not change the answer. Sum would count them twice.

Want to try a tiny question?
No pressure. Just try it.

Why can two overlapping blocks answer range minimum?

You can also keep scrolling
1 / 4
Range queries

One small step at a time.

This idea builds on these smaller ones. Pick any to revisit it here.

Search for the first yes.

no
no
no
yes
yes

In [no,no,no,yes,yes], the answer is the first yes, not merely any yes.

1 / 3
You've reached the end of these ideas.Try them without the labels