Problem Link - Maximum Subset Sum in Dynamic programming
Problem Statement:
Given N integers, you have to select a subset of these integers such that the sum of the subset is the largest compared to all other subsets.
Note: You might select an empty subset as well.
Approach:
- Iterate through the array.
- Accumulate the sum of all positive integers. Ignore negative integers and zeros.
- If all integers are negative, the maximum sum should be 0, as an empty subset provides the highest possible sum in such a case.
Complexity:
- Time Complexity:
O(N)
Traversing the array once. - Space Complexity:
O(1)
No extra space required.