Quad combination

Given an array of numbers arr and a number S, find 4 different numbers in arr that sum up to S.

Write a function that gets arr and S and returns an array with 4 indices of such numbers in arr, or null if no such combination exists. Explain and code the most efficient solution possible, and analyze its runtime and space complexity.

example:

findArrayQuadCombination([1, 2, 3, 4, 5, 6, 7, 8], 12);
// [0, 1, 2, 5]


Share Comments