POTD Solutions | 23 Oct’ 23 | Maximum Sum Increasing Subsequence Read Courses Practice Improve Improve Improve Like Article Like Save Article Save Report issue Report View all POTD Solutions Welcome to the daily solutions of our PROBLEM OF THE DAY (POTD). We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Dynamic Programming but will also help you build up problem-solving skills. POTD Banner Image We recommend you to try this problem on our GeeksforGeeks Practice portal first, and maintain your streak to earn Geeksbits and other exciting prizes, before moving towards the solution. POTD 23rd Oct Maximum Sum Increasing Subsequence Solve! Watch! POTD 23 October: Maximum sum increasing subsequenceGiven an array of n positive integers. Find the sum of the maximum sum subsequence of the given array such that the integers in the subsequence are sorted in strictly increasing order i.e. a strictly increasing subsequence. Example 1:Input: N = 5, arr[] = {1, 101, 2, 3, 100} Output: 106Explanation: The maximum sum of a increasing sequence is obtained from {1, 2, 3, 100} Example 2:Input: N = 4, arr[] = {4, 1, 2, 3}Output: 6Explanation: The maximum sum of a increasing sequence is obtained from {1, 2, 3}. Maximum Sum Increasing Subsequence using Dynamic Programming:This problem is a variation of the standard Longest Increasing Subsequence (LIS) problem. We need a slight change in the Dynamic Programming solution of LIS problem. All we need to change is to use sum as a criteria instead of a length of increasing subsequence. Step-by-step algorithm: Maintain a msis[] array, such that msis[i] stores the maximum sum of the increasing subsequence having last element as arr[i].Initialize msis[i] with arr[i]Iterate from i = 1 to i = N-1Check for all the indices j less than i such that (arr[i] > arr[j]) and update msis[i] is we can get greater sum using the subsequence ending at j.After iterating over the entire array, return the maximum element in msis.Below is the implementation of above approach: C++ class Solution { public: int maxSumIS(int arr[], int n) { // Your code goes here int i, j, max = 0; int msis[n]; /* Initialize msis values for all indexes */ for (i = 0; i < n; i++) msis[i] = arr[i]; /* Compute maximum sum values in bottom up manner */ for (i = 1; i < n; i++) for (j = 0; j < i; j++) if (arr[i] > arr[j] && msis[i] < msis[j] + arr[i]) msis[i] = msis[j] + arr[i]; /* Pick maximum of all msis values */ for (i = 0; i < n; i++) if (max < msis[i]) max = msis[i]; return max; } }; Java class Solution { public int maxSumIS(int arr[], int n) { // code here int i, j, max = 0; int msis[] = new int[n]; /* Initialize msis values for all indexes */ for (i = 0; i < n; i++) msis[i] = arr[i]; /* Compute maximum sum values in bottom up manner */ for (i = 1; i < n; i++) for (j = 0; j < i; j++) if (arr[i] > arr[j] && msis[i] < msis[j] + arr[i]) msis[i] = msis[j] + arr[i]; /* Pick maximum of all msis values */ for (i = 0; i < n; i++) if (max < msis[i]) max = msis[i]; return max; } } Python3 class Solution: def maxSumIS(self, Arr, n): max = 0 msis = [0 for x in range(n)] # Initialize msis values # for all indexes for i in range(n): msis[i] = Arr[i] # Compute maximum sum # values in bottom up manner for i in range(1, n): for j in range(i): if (Arr[i] > Arr[j] and msis[i] < msis[j] + Arr[i]): msis[i] = msis[j] + Arr[i] # Pick maximum of # all msis values for i in range(n): if max < msis[i]: max = msis[i] return max Javascript class Solution { maxSumIS(arr,n){ //code here let i, j, max = 0; let msis = new Array(n); // Initialize msis values // for all indexes for(i = 0; i < n; i++) msis[i] = arr[i]; // Compute maximum sum values // in bottom up manner for(i = 1; i < n; i++) for(j = 0; j < i; j++) if (arr[i] > arr[j] && msis[i] < msis[j] + arr[i]) msis[i] = msis[j] + arr[i]; // Pick maximum of // all msis values for(i = 0; i < n; i++) if (max < msis[i]) max = msis[i]; return max; } } Time Complexity: O(N ^ 2), where N is the length of the input arrayAuxiliary Space: O(N) POTD 23rd OctMaximum Sum Increasing SubsequenceRead Full Solution! Last Updated : 22 Nov, 2023 Like Article Save Article Previous POTD Solutions | 28 Oct’ 23 | Bleak Numbers Next POTD Solutions | 24 Oct’ 23 | Palindromic Partitioning Share your thoughts in the comments Add Your Comment Please Login to comment... Similar Reads POTD Solutions | 21 Oct’ 23 | Sum of all divisors from 1 to n POTD Solutions | 30 Oct’ 23 | Sum of XOR of all pairs POTD Solutions | 31 Oct’ 23 | Move all zeroes to end of array POTD Solutions | 15 Oct' 23 | Normal BST to Balanced BST POTD Solutions | 16 Oct’ 23 | Making A Large Island POTD Solutions | 17 Oct’ 23 | Transitive Closure of a Graph POTD Solutions | 18 Oct’ 23 | Eventual Safe States POTD Solutions | 19 Oct’ 23 | Level of Nodes POTD Solutions | 20 Oct’ 23 | Form a number divisible by 3 using array digits POTD Solutions | 22 Oct’ 23 | Number of paths Like M mrityuanjay8vae Follow Article Tags : Algorithms-Dynamic Programming GFG-POTD-Solutions Competitive Programming DSA Additional Information Vote for difficulty : Easy Normal Medium Hard Expert