Max Array Sum

  • + 1 comment
    def maxSubsetSum(arr):
            n = len(arr)
            if(n==0): return 0
            if(n==1): return arr[0]
            if(n==2): return max(arr[0],arr[1])
            dp1 = 0
            dp2 = 0
            for num in arr:
                    temp = max(dp1+num, dp2)
                    dp1 = dp2
        dp2 = temp
    return dp2