Open
Conversation
CheezItMan
reviewed
Apr 28, 2021
CheezItMan
left a comment
There was a problem hiding this comment.
Nice work Christabel, you hit the learning goals here. Well done.
| hashes = [] | ||
| strings.each do |word| | ||
| word_hash = {} | ||
| word = word.chars.sort #sort is O(n)? |
Comment on lines
+4
to
8
| # Time Complexity: O(2nm + p) where n is the length of the list passed to grouped_anagrams, and m represents the number of chars in each string and p is the number of unique char hashes | ||
| # == O(nm) | ||
| # Space Complexity: Um O(2n) == O(n) since I am creating an array equal to the length of the passed in list and the worst case size for the meta_hash is also the length of the passed in list? | ||
|
|
||
| def grouped_anagrams(strings) |
There was a problem hiding this comment.
I'd say this is O(n * m log m) where m is the number of chars in each string and n is the length of the array.
Comment on lines
+46
to
48
| # Time Complexity: O(3n) == O(n) where n is the length of the passed in list | ||
| # Space Complexity: O(n) since the worst case is that the elements hash is the full length of the passed in list | ||
| def top_k_frequent_elements(list, k) |
There was a problem hiding this comment.
This is O(n log n) because sorting is O(n log n)
Comment on lines
+74
to
79
| # Time Complexity: oh goodness. this is a mean question. I'm going with O(1) since the grid is always 9x9, but let me show my work here... | ||
| # O(9) == O(1) for checking for uniqueness in all rows and columns | ||
| # O(9) == O(1) for building the 2darray of all subgrid values | ||
| # O(9^2) == O(1) for checking for uniqueness in all subgrid values | ||
| # Space Complexity: for lack of more confident alternate logic, I'm going with the same answer as above, O(1) since the grid is a fixed size so the worst case for the created row, column, and subgrid hash are all worst case space complexities of O(9) and the array of subgrid values is a fixed size of O(81) | ||
| def valid_sudoku(table) |
There was a problem hiding this comment.
👍 You are correct that the time/space complexity is O(1)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hash Table Practice
Congratulations! You're submitting your assignment!
Comprehension Questions