-
Notifications
You must be signed in to change notification settings - Fork 37
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
Ports - Ngoc #18
base: master
Are you sure you want to change the base?
Ports - Ngoc #18
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.
Checklist
- Clean, working code
- Efficient code
- There's a solution that is
O(1)
space complexity that involves a trick. See if you can figure it out, and feel free to ping me on Slack if you're curious!
- There's a solution that is
- A detailed explanation of time and space complexity (explains what n stands for, explains why it would be a specific complexity, etc.)
- All test cases for the assignment should be passing.
# Space complexity: ? | ||
#Approach 1: | ||
# Time complexity: O(n^3) 3 nested loops | ||
# Space complexity: O(n^2) n is the number of rows and columns in the matrix being cloned |
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 true if the number of rows and columns are the same (i.e. the input matrix is a "square" matrix). However, if you allow the number of rows & columns to differ, you probably need to specify O(nm)
and define n
as the number of rows and m
as the number of columns.
# Time complexity: ? | ||
# Space complexity: ? | ||
#Approach 1: | ||
# Time complexity: O(n^3) 3 nested loops |
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.
Yep
end | ||
|
||
#Approach 2: | ||
# Time complexity: O(n^2) 2 nested loops |
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.
Same comment as above (O(nm)
instead of O(n^2)
), but well done! This second implementation is a significant improvement over the O(n^3)
implementation above.
No description provided.