My LeetCode Workflow: Stop Memorizing, Start Solving
I adopted a specific active recall loop that fundamentally changed how I approach technical interviews and daily coding. The logic is simple: explain the concept, step away, then rebuild from scratch.
The Active Recall Workflow
This is a practical tutorial for anyone stuck in the "easy problem plateau." Instead of just hitting 'Submit' and moving on, follow these steps:
1. Initial Solve: Solve the problem using any method.
2. The Verbal Audit: Close the IDE. Explain the solution out loud as if you're onboarding a junior dev. You must articulate every variable change and edge case.
3. The Buffer: Step away for 10 to 30 minutes. This break is non-negotiable; it clears the short-term "buffer" of the code.
4. The Blind Rebuild: Re-solve the problem from scratch. If you get stuck, you are only allowed to look at your own verbal explanation, never the code.
This process exposes "illusion of competence"—that feeling where you think you understand a solution because the code looks logical, but you can't actually derive it yourself.
Real-World Application: 3Sum
To show the difference, look at how my approach shifted. Initially, I was writing O(n³) disasters because I was just trying to make the test cases pass.
The "Brute Force" Mess:
def threeSum(nums):
res = []
nums.sort()
for i in range(len(nums)):
for j in range(i+1, len(nums)):
for k in range(j+1, len(nums)):
if nums[i] + nums[j] + nums[k] == 0:
triple = [nums[i], nums[j], nums[k]]
if triple not in res: # Inefficient O(n) check
res.append(triple)
return resThe issue here isn't just the time complexity; it's the lack of a mental model. By applying the "explain and delay" method, I forced myself to visualize the two-pointer movement on a sorted array.
The Optimized Result:
def threeSum(nums):
nums.sort()
res = []
n = len(nums)
for i in range(n - 2):
# skip duplicate fixed numbers
if i > 0 and nums[i] == nums[i-1]:
continue
left, right = i + 1, n - 1
while left < right:
total = nums[i] + nums[left] + nums[right]
if total < 0:
left += 1
elif total > 0:
right -= 1
else:
res.append([nums[i], nums[left], nums[right]])
while left < right and nums[left] == nums[left + 1]:
left += 1
while left < right and nums[right] == nums[right - 1]:
right -= 1
left += 1
right -= 1
return resUsing this as a deep dive into my own learning gaps made the difference between struggling with a Medium problem for two hours and solving it in ten minutes. It's a slower process at first, but it builds actual intuition.