Question Bank

JavaScript Pair-Sum Finder: Two Approaches Quiz

Difficulty: Medium

Two seeded ways to test whether two numbers in an array add up to a target (nested loop and Set complement), plus two companions on time complexity and on returning the actual pair instead of a boolean.

Question Bank
/

JavaScript Pair-Sum Finder: Two Approaches Quiz

JavaScript Pair-Sum Finder: Two Approaches Quiz

Two seeded ways to test whether two numbers in an array add up to a target (nested loop and Set complement), plus two companions on time complexity and on returning the actual pair instead of a boolean.

Question Bank
Medium
JavaScript
4 questions
quiz
arrays
hash-map
interview-prep

1,147 views

35

Implement sumFinder(arr, target) with a nested loop that returns true if any two distinct indices in arr sum to target, otherwise false.

Examples

Example 1:

Input: sumFinder([2, 3, 6, 1, 4, 5], 9)
Output: true
Explanation: 3 + 6 = 9 and 4 + 5 = 9, so the function returns true on the first matching pair.