A man is standing behind a table, with a row of teeth laid upon it. Each tooth is labelled with an integer. He asks you to identify the two teeth whose numbers sum to a specific target integer.
From a list of integers teeth, return the indices of the two teeth-numbers that add up to target. There will be precisely one valid pair of teeth-numbers.
Example 1
Input: teeth = [7, -1, 4], target = 6
Output: [0, 1]
Explanation: teeth[0] + teeth[1] = 7 + (-1) = 6
Example 2
Input: teeth = [1, 8, 14, 4], target = 9
Output: [0, 1]
Explanation: teeth[0] + teeth[1] = 1 + 8 = 9
Constraints
2 <= teeth.length <= 10^5-10^6 <= teeth[i] <= 10^6-10^6 <= target <= 10^6
CodeCrack Method Cheat Sheet + Scratch Pad
What’s this?
A six-step reference for working through unfamiliar coding problems, with an optional scratch pad for your approach.
Learn the method ↗- 1.Understand the Problem
- 2.Brute Force
- 3.Identify the Lower Bound
- 4.Find Overlapping Sub-Problems
- 5.Consider Data Structures
- 6.Iterate
No submissions yet
Run your code and your attempts will show up here.