Two Sum II
EasyThis is an extra practice problem. It doesn't have walkthrough slides. You can solve it with the pattern template you already know. Open the hints if you get stuck.
Question
Given a list of integers sorted in ascending order and a target value, return the indices of the two numbers that add up to the target.
Each input has at most one answer. If no pair adds up to the target, return an empty list.
Input: nums = [1, 2, 3, 4, 6], target = 6
Output: [1, 3]
The numbers at indices 1 and 3 are 2 and 4. 2 + 4 equals 6.
Input: nums = [2, 7, 11, 15], target = 9
Output: [0, 1]
Input: nums = [-3, -1, 0, 2, 5], target = 2
Output: [0, 4]
The numbers -3 and 5 add up to 2.
Input: nums = [1, 2, 3], target = 100
Output: []
No pair in the list adds up to 100.
Clarify the problem
What are some questions you'd ask an interviewer?
Understand the problem
Remember to understand the problem and plan your approach before you start coding.