BeginnerHabits & complexity
Say the brute force first
In an interview, start with the simple slow solution and its . 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 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: time, space.”
- “The repeated work is searching for the partner each time.”
- “A makes that lookup O(1), so overall 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 →