const getCombinations = (arr) => { let combinations = []; for (let i = 1; i < (Math.pow(2, arr.length)); i++) { let subsetArray = []; for (let j = 0; j < arr.length; j++) if (i & Math.pow(2, j)) subsetArray.push(arr[j]); let sum = subsetArray.reduce((a, b) => a + b); if (!combinations.includes(sum)) combinations.push(sum); } return combinations; } const solve = (arr) => { let max = arr.reduce((a, b) => a + b); let combinations = getCombinations(arr); for (let index = 1; index < max; index++) if (!combinations.includes(index)) return index; }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Discussion on: Daily Challenge #283 - Simple Missing Sum
For further actions, you may consider blocking this person and/or reporting abuse