The Quest Begins (The "Why")
I still remember staring at my screen, heart pounding, as the timer ticked down on a mock interview. The problem was Two Sum—seemingly simple, yet I kept jumping straight into code, writing a brute‑force O(n²) loop, then realizing I’d missed the edge case where the same element couldn’t be used twice. After thirty minutes of frustration, I closed the tab, feeling like I’d just lost a boss fight in Dark Souls without ever learning the pattern.
That night I asked myself: Why do I keep solving the same problems over and over without getting better? The answer hit me like a lightsaber to the wrist: I was treating LeetCode like a memorization exercise instead of a thinking workout. I needed a technique that forced me to understand before I typed.
The Revelation (The Insight)
The game‑changer turned out to be “Explain Out Loud Before You Code”—a rubber‑duck‑style ritual where you articulate the problem, the approach, and the reasoning in plain English (or to an actual duck, if you have one).
Here’s the exact wording I use, every single time:
“I need to solve [problem name]. The input is [describe input], and the output must be [describe output]. My plan is to [high‑level strategy] because [reason it works]. I’ll handle edge cases by [edge‑case handling]. The time complexity will be [Big O], and the space complexity will be [Big O].”
Saying that out loud forces me to confront gaps in my understanding before I write a single line of code. If I stumble on any part—especially the “why it works” or the edge cases—I know I need to revisit the concept, not just hack away.
Why does this work?
- Active recall – Retrieving the explanation from memory strengthens neural pathways far more than passive reading.
- Feynman effect – Teaching (even to a duck) reveals hidden assumptions.
- Pattern spotting – Verbalizing the strategy makes it easier to map the problem to known patterns (sliding window, two‑pointer, hash map, etc.).
Wielding the Power (Code & Examples)
The Struggle: Jumping Straight to Code
# Before: straight to coding, no explanation
def two_sum(nums, target):
for i in range(len(nums)):
for j in range(i+1, len(nums)):
if nums[i] + nums[j] == target:
return [i, j]
return []
What went wrong?
- I wrote O(n²) without thinking about a hash map.
- I missed the case where
numscould contain duplicates that need distinct indices. - I spent minutes debugging an off‑by‑one error that could have been avoided with a clear plan.
The Victory: Explain First, Then Code
Step 1 – Explain out loud (using the script above):
“I need to solve Two Sum. The input is a list of integers
numsand an integertarget. The output must be a list of the two indices whose values add up totarget. My plan is to iterate through the list once, storing each number’s complement (target - num) in a hash map as I go, because if we ever see a number that is already in the map, we’ve found the pair. I’ll handle the case where the same element can’t be used twice by checking the map before inserting the current number. The time complexity will be O(n), and the space complexity will be O(n).”
Step 2 – Code with confidence
# After: clear plan, then implementation
def two_sum(nums, target):
"""
Returns indices of the two numbers that add up to target.
Assumes exactly one solution exists.
"""
complement_map = {} # value -> index
for i, num in enumerate(nums):
complement = target - num
if complement in complement_map: # found the pair
return [complement_map[complement], i]
# store current number's index for future look‑ups
complement_map[num] = i
# According to the problem statement, this line is never reached.
return []
What changed?
- The explanation forced me to think of the hash‑map trick immediately.
- I caught the “same index twice” issue by noting we check the map before inserting.
- The code is clean, O(n), and I wrote it in under two minutes—no endless debugging loops.
Common Traps to Avoid
| Trap | What it looks like | Why it hurts | How to dodge it |
|---|---|---|---|
| Skipping the explanation | Opening the editor and typing the first idea that pops up | You solve the symptom, not the underlying pattern; you’ll forget it next time | Commit to the 2‑minute verbal script before touching the keyboard |
| Rambling without structure | “Um… I think I need to… maybe a loop? Or maybe sort?” | Vague talk gives false confidence; you still haven’t locked down a plan | Use the exact fill‑in‑the‑blanks script; it gives you a scaffold |
| Ignoring edge cases | Forgetting to mention duplicates, empty input, or negative numbers | Leads to hidden bugs that surface only in interview follow‑ups | Make edge‑case handling an explicit line in your explanation (“I’ll handle … by …”) |
Why This New Power Matters
Adopting the “Explain Out Loud” habit transformed my LeetCode grind from a memorization marathon into a skill‑building adventure.
- Speed: I now solve medium‑difficulty problems in 8‑12 minutes on average, because the thinking is done before I type.
- Retention: The patterns (hash map, two‑pointer, sliding window) stick because I’ve taught them to myself multiple times.
- Confidence: Walking into an interview, I know I can dissect any new problem on the spot—I’m not relying on a mental bank of memorized solutions.
In short, I went from feeling like a lost Padawan to wielding a lightsaber of clear thinking.
Your Turn: The Challenge
Pick any LeetCode easy problem you’ve struggled with before (e.g., Reverse Integer, Palindrome Number, Maximum Subarray).
- Set a timer for 2 minutes.
- Speak the explanation script out loud—to a wall, a pet, or that rubber duck on your desk.
- Only after the timer dings open your editor and write the solution.
Notice how the solution flows when the thinking is already done. Come back here and drop a comment with the problem you tackled and how the explanation changed your approach. May the force be with you—happy coding! 🚀
Top comments (0)