23. Maximum sum increasing subsequence
Last updated
Last updated
The problem can be found at the following link: Question Link
To find the maximum sum increasing subsequence, I use dynamic programming. I maintain a dp
array of the same size as the input array arr
. dp[i]
represents the maximum sum of increasing subsequence ending with arr[i]
.
To getting your Maximum Here is Bottom Up DP approach.
I initialize dp
with the values of arr
.
Then, I iterate through the elements of arr
.
For each element, I iterate through the previous elements and check if they are smaller than the current element.
If yes, I update dp[i]
to be the maximum between its current value and dp[j] + arr[i]
, where j
is the index of a smaller element.
Finally, I find the maximum value in the dp
array, which represents the maximum sum increasing subsequence.
Time Complexity: O(n^2)
, where n
is the size of the input array arr
. This is because we have a nested loop.
Auxiliary Space Complexity: O(n)
for the dp
array.
For discussions, questions, or doubts related to this solution, please visit our discussion section. We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star to the getlost01/gfg-potd repository.