The Quest Begins (The “Why”)
Honestly, I was stuck in a loop that felt worse than an infinite while(true). I’d grind LeetCode for hours, jump straight into coding, and then hit a wall — my solution would work for the sample cases but fail on the hidden edge cases. I’d stare at the screen, frustrated, wondering why I couldn’t just “see” the answer like the pros do. The turning point came after a particularly brutal mock interview where the interviewer kept asking, “Can you walk me through your thought process?” I mumbled something about hash maps and then realized I hadn’t actually explained anything — I’d just typed code and hoped for the best. That moment felt like losing a heart container in a dungeon: I knew I had the potential, but I was missing the right tool to unlock the next door.
The Revelation (The Insight)
The technique that finally cracked the problem was explaining my solution out loud — first to a rubber duck, then to an imaginary interviewer — before writing a single line of code. I know it sounds silly, but hear me out. When you force yourself to verbalize the algorithm, you expose gaps in your understanding that silent typing hides. It’s like using the Song of Time to slow down the world and see each step clearly.
Here’s the exact wording I used for every problem:
“First, I’ll restate the problem in my own words. Then I’ll outline the high‑level approach, name the data structures I’ll need, walk through a small example step‑by‑step, mention the time and space complexity, and finally note any edge cases I’ll handle.”
I kept a small rubber duck on my desk (yeah, the classic programmer’s sidekick) and literally talked to it. If I stumbled over a phrase or realized I’d forgotten to mention a case, I stopped, corrected my explanation, and only then opened my editor.
Wielding the Power (Code & Examples)
The Struggle (Before)
Problem: Two Sum – Given an array of integers nums and an integer target, return indices of the two numbers that add up to target.
My old habit: dive straight into coding.
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 []
I’d run it, see it work on the sample, feel good, and then get dinged on the hidden test with duplicate numbers or negative values because I never thought through the hash‑map optimization or the edge case where the same element can’t be used twice.
The Victory (After)
Now I explain first.
Explanation (out loud):
- Restate: Find two indices whose values sum to
target. - Approach: Scan the list once, storing each number’s complement (
target - num) in a hash map. If the current number is already a key in the map, we’ve found the pair. - Example:
nums = [2,7,11,15], target = 9.- i=0, num=2 → complement=7, map empty → store
{7:0}. - i=1, num=7 → 7 is in map → return
[map[7], 1]→[0,1].
- i=0, num=2 → complement=7, map empty → store
- Complexity: O(n) time, O(n) space.
- Edge cases: empty list, no solution, duplicate numbers, negative targets.
Only after that did I write the code:
def two_sum(nums, target):
"""
Returns indices of the two numbers such that they add up to target.
Assumes exactly one solution exists.
"""
complement_to_index = {} # value -> index
for i, num in enumerate(nums):
complement = target - num
if complement in complement_to_index:
return [complement_to_index[complement], i]
complement_to_index[num] = i
# According to the problem statement, this line is never reached.
raise ValueError("No two sum solution exists")
Notice the difference? The explanation forced me to think about the hash map before I typed a line, and the docstring now mirrors my verbalized assumptions.
Traps to Avoid
- Trap #1 – Skipping the explanation: Jumping straight into code leads to “I’ll figure it out as I go” syndrome. You’ll miss edge cases and waste time debugging.
- Trap #2 – Being vague: Saying “I’ll use a hash map” without saying what you store (key vs. value) is as useless as a sword without a hilt. Be precise: “store complement → index”.
Why This New Power Matters
Since adopting this habit, my interview performance changed dramatically. I went from sweating through silent coding sessions to walking interviewers through my thought process with confidence — just like Link confidently pulling the Master Sword from its pedestal. The interviewer sees not only that I can code, but that I can communicate my reasoning, which is often the differentiator at FAANG.
Beyond interviews, the technique sharpened my everyday problem‑solving. When I’m stuck on a bug at work, I now pause, explain the issue to my rubber duck (or a colleague), and the solution often appears before I even touch the keyboard. It’s saved me hours of frustrating guesswork and turned me into a more reliable teammate.
Your Turn – Grab Your Sword and Shield
Ready to try it? Here’s your quest:
- Pick a medium‑difficulty LeetCode problem you’ve avoided.
- Before opening your editor, speak the explanation out loud using the five‑step script above (feel free to talk to a rubber duck, a plant, or even your cat).
- Only after you feel the explanation is solid, write the code.
- Run the tests, note any missing edge cases, and iterate on your explanation before tweaking the code.
Comment below with the problem you tackled and how the explanation step changed your approach. I’m cheering you on — go crush those interviews like a hero reclaiming the Triforce! 🚀
Top comments (0)