Lesson 10 · 12 min
Debug Like a Teacher
What to do when tests fail — before asking for a full solution.
When your code fails
1. Compile errors first
Read the first error line. Common:
- missing
; - wrong return type
- used
mapwithout#include(harness usually includes bits) nums.size()compared badly with signed/unsigned
2. Trace one sample by hand
Pick the failing input. Fill a table: i | nums[i] | map state | action.
Your bug is the first row where paper ≠ code.
3. Check edge cases
- empty / single element
- all zeros
- negatives
- duplicates
- already sorted / reverse sorted
4. Hint ladder
Ask for Hint 1 → change approach → Hint 2 → still stuck → Hint 3. Full solution last.
CodeMentor's tutor follows this on purpose.
Rules to remember
- Fix compile before logic.
- Dry-run the failing test on paper.
- List edge cases before claiming AC.
- Don't jump to full solution on first WA.
Check yourself
1. Best first move after Wrong Answer?