GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Karteikarten

Maximum sum such that no two elements are adjacent

Suhas S Englisch 1 Karte

Karten in diesem Stapel (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;
    }
    }

Informationen

Beschreibung
Karteikarten am Maximum sum such that no two elements are adjacent, erstellt von Suhas S am 31/03/2018.
Erstellt von
Suhas S
Aufrufe
0
Bewertung

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck