Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR for max sum of non adjacent numbers #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion CheatSheets/flexbox-cheatsheet
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
Create a descriptive well formatted cheatsheet for all the things you should know about Flexbox
/**
* Given 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.
* So 3 2 7 10 should return 13 (sum of 3 and 10) or 3 2 5 10 7 should return 15 (sum of 3, 5 and 7).
* Answer the question in most efficient way.
* Input : arr[] = {5, 5, 10, 100, 10, 5}
Output : 110
Input : arr[] = {1, 2, 3}
Output : 4
*/

function maxSumOfNumbers(var values, var j) {
var initVal = values[0];
var curVal = 0;
var tempVal;
var k;

for (k = 1; k < j; k++)
{
if(initVal > curVal)
tempVal = initVal;
else
tempVal = curVal;

initVal = curVal + arr[k];
curVal = tempVal;
}

if(initVal > curVal)
return initVal;
else
return curVal;
}