Conversation
|
Grabbing this to grade! |
chimerror
left a comment
There was a problem hiding this comment.
Pretty good...
There is a bug in your otherwise correct anagrams solution that causes only the last string in each anagram group to be returned, not the entire group. This causes the automated tests to fail, so I am marking this Yellow to encourage you to fix that bug. If the bug is fixed, I'm fine with moving this up to Green.
I also added corrections to your complexity calculations, as well as some more hints on the sudoku problem.
| if word_sorted not in anagram_dict: | ||
| anagram_dict[word_sorted] = [string] | ||
| else: | ||
| anagram_dict[word_sorted] = [string] |
There was a problem hiding this comment.
Oof, this causes a pretty bad bug that means only the last string of each anagram group is returned, rather than all the strings in that group. I think you meant to append to the list here rather than replacing the value.
However, the solution is otherwise correct, so I'm only going to mark this Yellow. I will upgrade to Green upon this bug being fixed.
| Time Complexity: ? | ||
| Space Complexity: ? | ||
| Time Complexity: O(n) | ||
| Space Complexity: O(1) |
There was a problem hiding this comment.
As we possibly add an entry to anagram_dict for each word in strings (in the case no words are anagrams of each other), the space complexity here is O(n).
| Time Complexity: ? | ||
| Space Complexity: ? | ||
| Time Complexity: O(n) | ||
| Space Complexity: O(1) |
There was a problem hiding this comment.
Likewise, in this case we add an entry to most_common for each number in nums so the space complexity here is O(n).
| else: | ||
| if row.count(element) >1: | ||
| return False | ||
| if [row[i] for i in range(9)].count(element)>1: |
There was a problem hiding this comment.
I know this problem is optional but I just want to note that the list comprehension [row[i] for i in range(9)] will not actually return the columns, but just a copy of row again (since all rows are 9 elements long).
To get the columns, you'll have to iterate over table not row.
| return False | ||
| if [row[i] for i in range(9)].count(element)>1: | ||
| return False | ||
| if [table[i][j] for i in range(3) for j in range(3)].count(element) >1: |
There was a problem hiding this comment.
Likewise, this will always return the first subgrid ((0, 0) to (2, 2)) every iteration, so to fully solve this, you will likely need to more explicitly iterate through all the subgrids rather than using a list comprehension.
| row, column or 3x3 subgrid | ||
| Time Complexity: ? | ||
| Space Complexity: ? | ||
| Time Complexity: O(n2) |
There was a problem hiding this comment.
This would be correct (even given your current buggy implementation) if we were taking in arbitrary nxn grids, but as we are only taking in 3x3 grids, the run time is constant and thus O(1).
Hash Table Practice
Congratulations! You're submitting your assignment!
Comprehension Questions