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 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?
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?
nums
could contain duplicates that need distinct indices. Step 1 – Explain out loud (using the script above):
“I need to solve
Two Sum. The input is a list of integersnums
and 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 mapbeforeinserting the current number. The time complexity will be O(n), and the space complexity will be O(n).”
Step 2 – Code with confidence
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]
complement_map[num] = i
return []
What changed?
| 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 …”) |
Adopting the “Explain Out Loud” habit transformed my LeetCode grind from a memorization marathon into a skill‑building adventure.
In short, I went from feeling like a lost Padawan to wielding a lightsaber of clear thinking.
Pick any LeetCode easy problem you’ve struggled with before (e.g., Reverse Integer, Palindrome Number, Maximum Subarray).
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! 🚀