Sobes.tech
Junior — Senior

Finding a pair of array elements with a given sum

livecode

Task condition

Given an array of integers numbers and a target value requiredSum. Return any two numbers from the array whose sum equals requiredSum.

Input: numbers = [3, 4, 15, 2, 6], requiredSum = 10 Output: [2, 8] or [6, 4] — if such elements are present in the array.

public class Solution {
    public int[] twoSum(int[] nums, int targetSum) {
        // TODO
        return new int[0];
    }
}