Workspace Complement Lookup
0d
Problem-solving patterns

Complement Lookup

Use an equation to look up the missing partner.

Recognition signal

Two distinct items must meet a target sum.

Method

For each x, check whether target − x occurred earlier, then store x.

Worked example

With target 12 and [4, 8], reading 8 finds 4 in the table.

Common mistake

Reusing the current index can falsely solve a pair with equal values.