Skipping brute force
People jump straight to an optimized answer and get lost. Brute force gives you a foothold.
Before grinding patterns, rebuild the solving loop.
A lot of rust is not missing knowledge, it is missing rhythm. The first goal is to become calm and systematic again.
Skipping brute force
People jump straight to an optimized answer and get lost. Brute force gives you a foothold.
Not naming the repeated work
Optimization usually comes from spotting repeated scans, repeated comparisons, or missing memory.
Coding too early
If the idea is fuzzy, code just makes the confusion harder to inspect.
Problem idea: given an integer array nums, return true if any value appears at least twice.
[1,2,3,1] should return true[1,2,3,4] should return falseCompare every pair.
i, check all j > itruefalseRuntime: O(n^2)
Space: O(1)
What repeated work are we doing?
We keep re-checking whether we have seen a value before. A set gives us fast lookup.
class Solution: def containsDuplicate(self, nums: List[int]) -> bool: seen = set()
for num in nums: if num in seen: return True seen.add(num)
return FalseRuntime: O(n)
Space: O(n)
[] → false[7] → false[3,3] → true[1,2,3,4] → falseWhen a problem quietly asks, “have I seen this before?”, think about:
setdict or hash mapThat one reflex unlocks a lot of beginner interview problems.
Do these in order:
For each problem:
That last part matters. Recognition is weaker than recall.