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

🌊🌊🌊🌊🌊🌊🌊🌊 Kayla 🌊🌊🌊🌊🌊🌊🌊 #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
18 changes: 17 additions & 1 deletion lib/max_subarray.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,23 @@
// Space Complexity:

function maxSubArray(nums) {
throw new Error("Function not implemented yet...")

if (!nums.length) return null

let maxSoFar = -Infinity;
let maxEndingHere = 0;

for (num in nums){
maxEndingHere = maxEndingHere + nums[num]
// console.log(maxEndingHere)

if (maxSoFar < maxEndingHere) {
maxSoFar = maxEndingHere;
} else if (maxEndingHere < 0){
maxEndingHere = 0
}
}
return maxSoFar
}

module.exports = {
Expand Down
21 changes: 20 additions & 1 deletion lib/newman_conway.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,26 @@
// Space Complexity:

function newmanConway(num) {
throw new Error("Function not implemented yet...")

//from test, account for these base cases upfront:
if (num == 1) {
return "1";
} else if (num == 2) {
return "1 1";
} else if (num < 1) {
throw new Error;
}

let conwaySequence = [1, 1];

for (i = 3; i <= num; i++) {
const lastValue = conwaySequence[i - 2];
const newValue = conwaySequence[lastValue - 1] + conwaySequence[i - lastValue - 1];
conwaySequence.push(newValue);
}

return conwaySequence.join(' ');

}

module.exports = {
Expand Down