Last active
August 30, 2020 18:23
-
-
Save trunkslamchest/56cbdd616c63d6508d16e5d1d617606c to your computer and use it in GitHub Desktop.
blog30_solution6.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var minSubsequence = function(nums) { | |
let sum = nums.reduce((a, b) => a + b ) | |
let subSum = 0 | |
let sub = [] | |
nums.sort((a, b) => a - b) | |
for(i = nums.length - 1; i >= 0; i--){ | |
if(sum >= subSum) { | |
subSum += nums[i] | |
sum = sum - nums[i] | |
sub.push(nums[i]) | |
} else { | |
break | |
} | |
} | |
// return the subsequence once we break out of the for loop | |
return sub | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment