Back to problems

Solve 15 common interview problems

Algorithm · Apple · Easy

You are given an array of integers nums and an integer target. Find two distinct indices i and j such that nums[i] + nums[j] == target, and return them as [i, j]. Every input is guaranteed to contain exactly one such pair. Return the answer with the smaller index first. Example 1: Explanation: nums[0] + nums[3] = 3 + 5 = 8. Example 2: Explanation: The two 6 values at positions 1 and 3 add up to 12, so the smaller index is returned first. Example 3: Constraints: 2 <=…

Checking your access…