Skip to content

Conversation

marks214
Copy link

No description provided.

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

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

This is working Aimee, but see my notes on Newman-Conway. Your solution is inefficient and doesn't use dynamic programming to make it faster.

Comment on lines +2 to 5
// Time Complexity: O(n) - we iterate n times through nums, which is an array of length n
// Space Complexity: O(1) - we have constant space complexity, with variables max_result and temp_max

function maxSubArray(nums) {

Choose a reason for hiding this comment

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

👍

Comment on lines +1 to +5
// Newman-Conway sequence: P(n) = P( P(n - 1)) + P(n - P(n - 1)), with intial conditions P(1)=1 and P(2)=1
// Time Complexity: O(n) - there is a for loop in newmanConway that will run n number of times. The function p that it calls on has a time complexity of O(1) because it directly looks up the values in the array it's adding to.
// Space Complexity: O(n) - both the newmanConway and p functions add n elements to their data structures.

// Time Complexity:
// Space Complexity:
newmanConway = (num) => {

Choose a reason for hiding this comment

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

⚠️ , this works, but because you're not using your memo pValues, your recursion is making this O(3^n) .

Instead you should loop from 1 to num calculating the newmanConway value and storing it in your "memo." for lookup later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants