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

Ports - Ngoc #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Ports - Ngoc #18

wants to merge 1 commit into from

Conversation

lebaongoc
Copy link

No description provided.

Copy link

@mmcknett mmcknett left a 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!
  • 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
Copy link

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
Copy link

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
Copy link

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.

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