Maximum Sum of Non-Adjacent Elements

1D DP DSA practice problem on Onlearn.

Difficulty: medium.

Topics: Maximum sum of non-adjacent elements (Dynamic Programming Problem), Dynamic Programming, Recursion, Memoization, Tabulation, Space Optimization, Time Complexity, Space Complexity, Arrays, Subsequences, complexity analysis, dynamic programming, memoization, tabulation, space optimization, recursion, Subsequence Problems, DP on Subsequences / Subsets, DP State Management.

Maximum Sum of Non Adjacent Elements Problem Statement Given an array arr of N positive integers, find the maximum possible sum of a subsequence such that no two elements of the subsequence are adjacent in the original array. A subsequence is formed by deleting zero or more elements from the original array, maintaining the relative order of the remaining elements. Input Specification The input consists of: An array of N positive integers. Output Specification Return a single integer, the maximum sum of a non adjacent subsequence. Sample Test Case Input: Output: Explanation: The possible non adjacent subsequences are: [2, 4, 9] Sum = 15 (Invalid: 2 and 4 are adjacent to each other if we consider the original array indices, and also 4 and 9 are not adjacent, but 2 and 1 are adjacent, if we pick 2, we can