Read the constraints first: how I pick the pattern in under 2 minutes
Most people read the story in a problem and skip the constraints. The story is decoration. The constraints tell you the complexity you are allowed, and the complexity tells you the pattern. This is the routine I use, and the one I have been teaching in mocks for six years. Step 1: constraints → your budget Rough rule: a judge does about 10^8 simple operations per second in C++ or Java. So: n ≤ 20 : exponential is…