Skip to content
6
0
:
0
0

Inventory Sum Check

Easy

Hash

In "Inventory Sum Check", you are given a list of integer values and a target total. Find the two different positions whose values add up to the target.

Return the two indices in any order. You may assume there is exactly one valid answer.

Example 1

Input:nums = [9,14,20,11,29], target = 20
Output:[0,3]

For input nums = [9,14,20,11,29], target = 20, Indices [0,3] are correct because nums[0] + nums[3] = 9 + 11 = 20. Therefore, return [0,3].

Example 2

Input:nums = [12,18,17,27,18], target = 35
Output:[1,2]

For input nums = [12,18,17,27,18], target = 35, Indices [1,2] are correct because nums[1] + nums[2] = 18 + 17 = 35. Therefore, return [1,2].

Constraints

  • 2 <= nums.length <= 104
  • -109 <= nums[i] <= 109
  • -109 <= target <= 109
  • Exactly one valid pair exists.
solution.js
Loading...

Test Cases (2)

Test Case 1
Input:
[9,14,20,11,29], 20
Expected Output:
[0,3]
Test Case 2
Input:
[12,18,17,27,18], 35
Expected Output:
[1,2]