0

loop through an unsorted array and find pairs whose sum of those two pairs is equal to the target, for instance an array like: [1, 2, 4, 3, 7, 6, 2, 1, -4] and target is equal to 5

function findPairs(array, goal) {
  // implement your optimal solution here!
  return [];
}

findPairs([1, 2, 4, 3, 7, 6, 2, 1, -4], 5);

I solved it with two nested for-loops which is not an optimal solution because the nested loop's complexity is O(n²).

  • And also https://stackoverflow.com/questions/1494130/find-all-pairs-of-integers-within-an-array-which-sum-to-a-specified-value – Nick Oct 22 '22 at 11:45

0 Answers0