Skip to content

Instantly share code, notes, and snippets.

@vinnymac

vinnymac/README.md

Created Sep 16, 2019
Embed
What would you like to do?
Daily Coding Problem #1

Problem 1

Given a list of numbers, return whether any two sums to k. For example, given [10, 15, 3, 7] and k of 17, return true since 10 + 7 is 17.

Bonus: Can you do this in one pass?

function checkSums(numbers, k) {
const possibleSolutions = new Set()
for (let number of numbers) {
if (possibleSolutions.has(number)) return true
possibleSolutions.add(k - number)
}
return false
}
// checkSums([10, 15, 3, 7], 17) -> true
// checkSums([1, 2, 3, 4], 8) -> false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment