-
Notifications
You must be signed in to change notification settings - Fork 76
Spruce - Angela Fan #51
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
base: master
Are you sure you want to change the base?
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.
Nice work! I've left a few notes about complexity calculations and some hints for the sudoku problem; overall this is a green =]
@@ -2,28 +2,75 @@ | |||
def grouped_anagrams(strings): | |||
""" This method will return an array of arrays. | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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))
|
||
def top_k_frequent_elements(nums, k): | ||
""" This method will return the k most common elements | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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