Two Sum II (Sorted)
Read the lesson → understand the pattern → then code. Tutor works offline (built-in teacher); optional Cursor/Gemini keys upgrade chat quality.
Topic refresher: Two Pointers — Two Indices, One Rule
Move left/right based on a condition instead of checking all pairs.
int L = 0, R = n - 1;
while (L < R) {
int sum = a[L] + a[R];
if (sum == target) { L++; R--; }
else if (sum < target) L++;
else R--;
}MediumTwo PointersLeetCode #167
Two Sum II
1-indexed sorted array. Two pointers from ends — no hash needed.
Examples
Example 1
Input
4 9 2 7 11 15
Output
1 2
Example 2
Input
3 6 2 3 4
Output
1 3
Stuck? Take a nudge
C++17Autosaves