GoConqr has a new look! Let us know what you think.

Flashcards

Maximum sum such that no two elements are adjacent

Suhas S English 1 card

Cards in this deck (1)

  1. 1Given an array of positive numbers, find the maximum sum of a subsequence with the constraint that no 2 numbers in the sequence should be adjacent in the array. Input : arr[] = {1, 2, 3} Output : 4int FindMaxAdjacentSum(int a[],int n){
    int excl = 0;
    int incl = a[0];
    for(int i = 1; i< a.length; i++){
    int excl_new = (incl>excl)?incl:excl;
    incl = excl + arr[i];
    excl = excl_new;
    }
    }

Information

Description
Flashcards on Maximum sum such that no two elements are adjacent, created by Suhas S on 31/03/2018.
Created by
Suhas S
Views
0
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?