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

C16 - Afina Walton #1

Open
wants to merge 2 commits 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
16 changes: 13 additions & 3 deletions lib/max_subarray.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@

// Time Complexity:
// Space Complexity:
// Time Complexity: O(N)
// Space Complexity: O(1)

function maxSubArray(nums) {
throw new Error("Function not implemented yet...")
if (nums.length === 0) return null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


let maxSubarray = nums[0];
let currentSubarrayMax = nums[0];

for (let i = 1; i < nums.length; i++) {
currentSubarrayMax = Math.max(currentSubarrayMax + nums[i], nums[i]);
maxSubarray = Math.max(maxSubarray, currentSubarrayMax);
}

return maxSubarray;
}

module.exports = {
Expand Down
20 changes: 17 additions & 3 deletions lib/newman_conway.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@

// Time Complexity:
// Space Complexity:
// Time Complexity: O(N)
// Space Complexity: O(N)

function newmanConway(num) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

throw new Error("Function not implemented yet...")
if (num === 0) throw new Error;
if (num === 1) return "1";

let result = Array(num);

result[1] = 1;
result[2] = 1;
for (let i = 3; i <= num; i++) {
result[i] = result[result[i - 1]] + result[i - result[i - 1]];
}

result.shift();
console.log(result);

return result.join(' ');
}

module.exports = {
Expand Down
Loading