Part 1 · Module 3
Brute force first
Try every option first. Then count the steps, read the constraints, and find the work that gets repeated.
4 lessons · 40 min in total
When to reach for it
- Every pair
- When a problem asks about two items and the input is small. It's also the reference to check a faster solution against.
- Count the steps
- Before coding a brute force solution. Multiply the sizes of nested loops and compare with 10⁸.
- Constraints set the speed
- After reading the problem, before choosing an approach. The upper bound gives the speed, the lower bound gives the edge cases.
- Repeated work
- When your brute force is right but too slow. Ask: what does the inner loop compute that you already knew?
Lessons
Module challenge
Coding problems that test every pattern in this module.