-
Notifications
You must be signed in to change notification settings - Fork 34
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
water - mackenzie #19
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.
Your largest subarray works, but isn't using dynamic programming and has a pretty bad runtime. See my comments and let me know if you have questions or need help working through it.
We can review it if needed.
while i < nums.length do | ||
max_ending_here = max_ending_here + nums[i] | ||
if (max_so_far < max_ending_here) | ||
max_so_far = max_ending_here | ||
end | ||
i+=1 | ||
end |
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.
You can do this without the nested loop. Think about how you could use same saved values, like the largest subarray so far and the largest ending at the current index and how that could work.
# Time Complexity: O(n!)? You only go throught the each with index n times, but the inner loop completes decrementing number of loops... | ||
# Space Complexity: O(1), no additional data structures created outside of 2 variables each times | ||
def max_sub_array(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.
# Time complexity: O(n) | ||
# Space Complexity: O(n), always creating 1 array num + 1 length long and 1 string proprtionate to n | ||
# P(1) = 1 | ||
# P(2) = 1 | ||
# for all n > 2 | ||
# P(n) = P(P(n - 1)) + P(n - P(n - 1)) | ||
# 1 1 2 2 3 4 4 4 5 6 7 7…. | ||
def newman_conway(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.
👍
No description provided.