AAlgoLoopSpaced repetition for LeetCode

Math / Number Theory

Math problems lean on number theory, combinatorics, and arithmetic insight — GCDs, primes, modular arithmetic, overflow — rather than a data structure. The win usually comes from a formula or property that replaces a loop.

10 LeetCode problems solved with the Math / Number Theory pattern. Practice them with spaced repetition so the pattern sticks.

See the full solution

The complete approach, reference solutions in 5 languages, and a step-by-step visualization — then add this problem to your spaced-repetition schedule.

Start free →