MaxSum Subsequence - Nonadjacent Elements

Find the maximum sum of a subsequence made up of nonadjacent elements in an array.

Statement

Find the maximum sum of a subsequence in a given array such that no consecutive elements are part of this subsequence.

Examples

Consider the following examples:

  • In the example below, the maximum sum of a subsequence with no consecutive elements is 2525:

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.