-
Notifications
You must be signed in to change notification settings - Fork 29
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
Elle #6
base: master
Are you sure you want to change the base?
Elle #6
Conversation
Fixed. |
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.
Nice work, you hit all the time and space complexities and solved both problems using a dynamic programming approach. Well done. The only criticism I could find was the use of p
, s
and n
for variable names.
# Space Complexity: ? | ||
# Time Complexity: O(n) where n is the length of the array | ||
# Space Complexity: O(1) | ||
|
||
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.
👍 Nicely done!
return string_solution[0...-1] | ||
end | ||
|
||
def p(n, s) |
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.
Just noting the variable names are not meaningful here.
return s[n-1] if s[n-1] | ||
|
||
if (n == 2) && !s[2-1] | ||
s[2-1] = 1 |
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.
Why not just do s[1] = 1
if (n == 2) && !s[2-1] | ||
s[2-1] = 1 | ||
else | ||
s[n-1] = p(p(n - 1, s), s) + p(n - p(n - 1, s), s) |
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.
Nice both recursive and efficient solution.
For max_subarray, my method is passing all of the provided tests but there's another case I wrote a test for and it's failing. Will try to debug tomorrow (Sunday).