Skip to content

Conversation

@dev-elle-up
Copy link

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

@dev-elle-up
Copy link
Author

Fixed.

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.

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.

# Time Complexity: O(n) where n is the length of the array
# Space Complexity: O(1)

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.

👍 Nicely done!

return string_solution[0...-1]
end

def p(n, s)

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

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)

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.

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