You are viewing a single comment's thread. Return to all comments →
Simple TypeScript/JavaScript 4 line solution
function maxSubsetSum(a: number[]): number { const dp: number[] = []; for (let i = 0; i < a.length; i++) dp[i] = Math.max(a[i], i == 0 ? 0 : dp[i - 1], a[i] + (i < 2 ? 0 : dp[i - 2])); return Math.max(...dp); }
Seems like cookies are disabled on this browser, please enable them to open this website
Max Array Sum
You are viewing a single comment's thread. Return to all comments →
Simple TypeScript/JavaScript 4 line solution