21. Two Sum II - Input Array Is Sorted
easyAsked at PlaidGiven a sorted array, find two indices whose values sum to a target. Plaid asks this to verify you exploit sortedness — same shape as finding two transactions on a sorted balance-history that net to a target gap.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Plaid loops.
- LeetCode Discuss (2026)— Plaid OA — sorted variant.
- Glassdoor (2025)— Plaid intro.
Problem
Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Return the indices (1-indexed) of the two numbers. The tests are generated such that there is exactly one solution. You may not use the same element twice.
Constraints
2 <= numbers.length <= 3 * 10^4-1000 <= numbers[i] <= 1000numbers is sorted in non-decreasing order.Exactly one solution exists.
Examples
Example 1
numbers = [2,7,11,15], target = 9[1,2]Example 2
numbers = [-1,0], target = -1[1,2]Approaches
1. Hash map (ignoring sortedness)
Same as LC 1.
- Time
- O(n)
- Space
- O(n)
function twoSum(nums, target) {
const seen = new Map();
for (let i = 0; i < nums.length; i++) {
if (seen.has(target - nums[i])) return [seen.get(target - nums[i]) + 1, i + 1];
seen.set(nums[i], i);
}
}Tradeoff: Works but wastes the sortedness. Plaid would dock you for ignoring the precondition.
2. Two pointers from both ends
Lo and hi pointers. If sum is too small, move lo up. Too large, move hi down. Constant extra space.
- Time
- O(n)
- Space
- O(1)
function twoSum(nums, target) {
let lo = 0, hi = nums.length - 1;
while (lo < hi) {
const s = nums[lo] + nums[hi];
if (s === target) return [lo + 1, hi + 1];
if (s < target) lo++;
else hi--;
}
}Tradeoff: Linear time, O(1) space. Each step rules out one row of the implicit sum matrix — that's why correctness holds.
Plaid-specific tips
Plaid grades this on whether you exploit sortedness. Articulate the invariant out loud: 'we've ruled out all pairs (i, j) with i < lo or j > hi based on the current sum comparison.' Bonus signal: connect it to finding two balance points on a sorted history that net to a target delta.
Common mistakes
- Forgetting the 1-indexed return — easy to slip back into 0-indexed.
- Using sort() on already-sorted input — wastes O(n log n) and may not be in-place.
- Off-by-one on the loop condition (<= vs <).
Follow-up questions
An interviewer at Plaid may pivot to one of these next:
- What if duplicates are allowed and you need all pairs?
- Three Sum (LC 15) — same pattern with an outer loop.
- Two Sum on a stream where new numbers arrive.
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why two pointers, not binary search?
You could binary-search for (target - nums[i]) for each i — that's O(n log n). Two pointers is O(n) and uses the same monotonicity.
Why does each step rule out a row?
If nums[lo] + nums[hi] < target, no nums[lo] + nums[j] (j < hi) can equal target either — they're all smaller. So we can drop lo.
Practice these live with InterviewChamp.AI
Drill Two Sum II - Input Array Is Sorted and other Plaid interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →