Back to Hub
Completed: 0 / 10
Practice Lab
Live Coding Drills
Write code, run tests, and learn the core patterns with instant feedback.
Practice Status
Attempts
0
Completed
0/10
Top mistakes
No mistakes tracked yet.
Pattern Coach
Follow the flow- 1Read the pattern cardWhat it is, when to use it, traps.
- 2Answer the thinking promptsMake the invariant explicit.
- 3Write a short plan3 steps max, then code.
- 4Run tests + fixLearn from mistakes fast.
Tip: Say the invariant out loud before you code.
Two pointers
Two Sum (Sorted)
Given a sorted array and a target, return true if a pair sums to the target.
+120 XP
Function signature
function hasPairSum(nums, target) {}hasPairSum.jsjavascript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Press Escape then Tab to leave editor
Pattern card
Two pointers moving inward while keeping an invariant.
Use it when
Sorted arrays or monotonic pointer moves.
Common traps
- • Off-by-one bounds
- • Moving the wrong pointer
Hints
Try a hint, then re-run tests. Use the next hint only if you still fail.
- • Sorted array means pointer moves change the sum directionally.
- • Shrink the window when sum is too big.
Common mistakes
- • Moving both pointers at once.
- • Forgetting to stop when left >= right.
Critical thinking
Questions to answer before you code
- • What invariant keeps the window valid?
- • Which pointer move reduces the sum?
Plan
- • Set left=0, right=n-1.
- • Move pointers based on sum vs target.
- • Stop when left >= right.
Edge cases
- • Empty array
- • Two elements only
- • Target not possible
Target: O(n) time, O(1) space
If you are stuck, rewrite the plan in your own words before coding.
Test results
Run tests to see results.
Code executes locally in your browser. Keep it focused and safe.