Pair With Target Sum
Difficulty: Easy · Pattern: Two Pointers · Concept: General Coding (DSA) — Core Patterns to Drill
Given a list of integers already sorted in ascending order and a target, find the indices of the two numbers that add up to target. Assume exactly one valid pair exists, and that you can't use the same element twice.
The brute-force answer checks every pair — . Sorted input is the tell that a smarter approach exists: two pointers, one starting at each end, moving inward based on whether the current sum is too big or too small.
Your task: implement pair_with_target_sum(arr, target), returning [i, j] with i < j.
Next: Three Sum to Zero (a harder variant), or continue to Longest Run of Unique Characters