-
Notifications
You must be signed in to change notification settings - Fork 77
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
Pine - Ainur #49
base: master
Are you sure you want to change the base?
Pine - Ainur #49
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.
Pretty good!
I left quite a few comments, but most importantly there's a slight bug in your return value for the anagrams problem that causes the tests to fail. There's also a naming issue with your sudoku solution that you can fix to get what seems to be a working implementation to pass those tests.
Other comments I left relate to your complexity calculations and a very minor style note.
Unfortunately with the failing tests, I am marking this Yellow. Simply fix those failing tests and I'll gladly move up to Green!
result.get(key).append(word) | ||
else: | ||
result[key] = [word] | ||
return result.values() |
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.
Unfortunately, this does not return a list, which is why the automated tests are failing. You can get a list from a call to values()
by wrapping this in the list()
function.
I'm a bit of a stickler for the automated tests passing, so I'll have to mark this Yellow for now, but just fix this bug and this part will be good enough for Green.
@@ -2,18 +2,50 @@ | |||
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(nklog(k)), where k is the length of the string |
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.
This is a correct answer, but we can make a simplifying assumption here. Since we know the elements of strings
are English words, their size is rather constrained. On average words in English have about 5 letters on average, which is going to be quickly dwarfed by the number of strings in strings
, which is unbounded and could be in the hundreds or thousands.
With that simplifying assumption, we can ignore the k
part of this and just say it is O(n).
Time Complexity: ? | ||
Space Complexity: ? | ||
Time Complexity: O(nklog(k)), where k is the length of the string | ||
Space Complexity: O(log(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.
This is incorrect. We still have to add a key-value pair to result
for every element of strings
, which means there will be O(n) key-value pairs added, giving us a space complexity of O(n).
if not nums: | ||
return [] | ||
count = {} | ||
frequency = [[] for i in range(len(nums)+1)] |
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.
Small style nitpick: I usually prefer to wait to initialize a variable right before it is used, as that reduces the need to scroll back up. So I would put line 33 here down right before the for
loop on line 39.
Space Complexity: O(n) | ||
# """ | ||
from collections import defaultdict | ||
def validSudoku(board): |
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.
This actually looks like a working implementation! However because your function is called validSudoku
in camel-case instead of valid_sudoku
as our automated tests expect, the tests are failing.
This problem is optional, but if you would like to pass the tests when you make that fix to get the anagram tests passing, just change the name here.
""" | ||
pass | ||
Time Complexity: o(n^2) | ||
Space 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.
I think your time complexity answer would be true if we accepted arbitrary sized grids of nxn, but luckily in this case we only accept 3x3 grids, so we can say this is O(1) for both time and space complexity.
However, your space complexity would be off in the nxn in case because we are also using up to n^2 elements in cols
, rows
, and squares
(9 keys for each column/row/subgrid with up to 9 values each).
Regardless, this is an optional problem.
Hash Table Practice
Congratulations! You're submitting your assignment!
Comprehension Questions