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

water - mackenzie #19

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

water - mackenzie #19

wants to merge 3 commits into from

Conversation

mvlofthus
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.

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.

Comment on lines +21 to +27
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

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.

Comment on lines +2 to 4
# 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)

Choose a reason for hiding this comment

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

⚠️ I think this is O(n^2) due to the tested loop. You can do it without the inner loop, and just with some if-else statements.

Comment on lines +3 to 10
# 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)

Choose a reason for hiding this comment

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

👍

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