Brute Force First, Then Improve
40 min · Intermediate
The brute-force solution is the simplest correct approach, usually trying every possibility. In an interview you state it first, give its complexity, and then improve it step by step with a small set of standard optimization levers, explaining each trade-off aloud.
Topics in this lesson
- Why stating brute force earns credit
- The five optimization levers
- Talking through the trade-off as you improve
- Worked example: pair sum from O(n²) to O(n)
- When to stop optimizing
Interview questions this lesson answers
- Why should you mention the brute-force solution first?
- Should you always code the brute force?
- How do you find what to optimize in a brute force?
- What are the main optimization levers?
- When does hashing help?
- When does sorting help?
- When do two pointers work?
- When do prefix sums help?
- When does binary search help beyond sorted arrays?
- How do you talk through a trade-off?
Sign in free to continue this lesson
Create a free account to read every lesson, practise with the exercises and keep track of your progress.