-
Notifications
You must be signed in to change notification settings - Fork 8
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
Aimee 👾 - Fire 🔥 #2
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
// 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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
// 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) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
No description provided.