Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Pine - Ainur #49

wants to merge 3 commits into from

Conversation

adjayanbaeva
Copy link

Hash Table Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
Why is a good Hash Function Important?
How can you judge if a hash function is good or not?
Is there a perfect hash function? If so what is it?
Describe a strategy to handle collisions in a hash table
Describe a situation where a hash table wouldn't be as useful as a binary search tree
What is one thing that is more clear to you on hash tables now

Copy link

@chimerror chimerror left a 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()

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

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))

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)]

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):

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)

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants