You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Problem : Given an array of ‘N’ positive integers, we need to return the maximum sum of the subsequence such that no two elements of the subsequence are adjacent elements in the array.
// there can be two cases for an element, either we keep it, so we discard the element adjacent to it, or else we discard the current element so that we can move ahead and make decision for the adjacent element and then return the maximum of both of these choices
23
+
int pick = arr[ind] + maximumNonAdjacentSum(ind - 2, arr, dp);
24
+
int nonPick = maximumNonAdjacentSum(ind - 1, arr, dp);
0 commit comments