BeginnerHabits & complexity
Say the brute force first
In an interview, start with the simple slow solution and its Big O. It shows you understand the problem and gives you something to improve.
The idea
Jumping straight to a clever idea is risky: if it's wrong, you have nothing. Stating the brute force first proves you understand the problem, gives a correct fallback, and makes the optimization a natural next step.
You usually don't need to code it. Describe it, give its complexity, then ask “where is the repeated work?”: that question leads to most optimizations.
Worked example
Two Sum in an interview
- “The brute force checks every pair: O(n²) time, O(1) space.”
- “The repeated work is searching for the partner each time.”
- “A hash map makes that lookup O(1), so overall O(n) time and O(n) space. Shall I code that?”
How to spot it
- Every interview problem, right after you've clarified the question.
Common mistakes
- Coding the brute force fully when the interviewer wants the optimal one: describe it, then move on.
- Skipping the complexity of the brute force.
Practise it
Go further
Up next for you · Beginner
“Have I seen this?” is a set →