re: How do you find all pairs of an integer array whose sum is equal to a given number? VIEW POST


Another solution would be to use a map(or a dictionary in python, AFAIK) where each key would follow this rule: sum - list[i];

for (let i = 0; i < len; i++) {
   const k = sum-list[i];
  if (map.has(k))
     console.log(k, map.get(k))
  else map.set(k, list[i]);
Code of Conduct Report abuse