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²).