Challenge 📝
Given an array of integers arr
, find a subsequence (not necessarily contiguous) of arr
that has the largest sum. Return the sum of this subsequence.
Examples:
// Example 1
let arr = [-2, 1, -3, 4, -1, 2, 1, -5, 4];
console.log(maxSumSubsequence(arr)); // Output: 6
// Explanation: The subsequence [4, -1, 2, 1] has the largest sum (6).
// Example 2
arr = [1, 2, 3, -2, 5];
console.log(maxSumSubsequence(arr)); // Output: 9
// Explanation: The subsequence [1, 2, 3, -2, 5] has the largest sum (9).