Conversation
kelsey-steven-ada
left a comment
There was a problem hiding this comment.
Nice work! I've left a few notes about complexity calculations and some hints for the sudoku problem; overall this is a green =]
| Each subarray will have strings which are anagrams of each other | ||
| Time Complexity: ? | ||
| Space Complexity: ? | ||
| Time Complexity: O(n^2) |
There was a problem hiding this comment.
We want to be careful about reusing the same variable for complexity calculations. It seems like n is being used as both the number of strings in strings and the number of letters in a word. I would suggest using something like m for the number of letters in a word for clarity.
Looking at the overall Big O, and line 12 in particular, calling the sorted function on a list is an O(m*log(m)) operation. If n is the length of the input strings and m is the length of a word, our overall time complexity would be O(n*m*log(m))
| In the case of a tie it will select the first occuring element. | ||
| Time Complexity: ? | ||
| Space Complexity: ? | ||
| Time Complexity: O(n) |
There was a problem hiding this comment.
Since this solution uses sorted on line 33, our overall time complexity would be O(n) to fill counts + sorted's complexity O(n*log(n)). That gives us O(n + n*log(n)), which we'd simplify to O(n*log(n)).
| for i in range(1, 10): | ||
| if str(i) not in row: | ||
| return False |
There was a problem hiding this comment.
The Sudoku problem is optional, so no need to revisit, but something to consider if you were wondering about the test failures: this function will return False if a row does not contain all the numbers 1-9.
A row can be valid without being fully filled in yet, and when valid_row is called from valid_subgrid it looks like the row input is 3 items long and would always return false. We want to be sure that there are no duplicate values in a given row or subgrid. One way to do that could be to create a frequency map of the characters in the row, then check that no character other than . has a count greater than 1.
| return False | ||
| for i in range(0, 9, 3): | ||
| for j in range(0, 9, 3): | ||
| if not valid_subgrid(table[i:i+3], table[j:j+3]): |
There was a problem hiding this comment.
It doesn't look like the function declaration for valid_subgrid takes in a second parameter, I'm not sure the second slice here table[j:j+3] gets validated.
Hash Table Practice
Congratulations! You're submitting your assignment!
Comprehension Questions