FrontendChallenges is a collection of frontend interview questions and answers. It is designed to help you prepare for frontend interviews. It's free and open source.
You are given an array of integers nums and an integer target. Write a function that returns the indices i and j such that nums[i] + nums[j] == target and i != j.
You can assume that each input will have exactly one pair of indices i and j that satisfy the condition.
Make sure to return the indices with the smaller index first.
Info
Question
You are given an array of integers
nums
and an integertarget
. Write a function that returns the indicesi
andj
such thatnums[i] + nums[j] == target
andi != j
.You can assume that each input will have exactly one pair of indices
i
andj
that satisfy the condition.Make sure to return the indices with the smaller index first.
Constraints:
nums.length
≤ 1000nums[i]
≤ 10,000,000target
≤ 10,000,000Example Usage:
Template
index.ts
index.test.ts