Conversation
Implement Hash Set (design-hashset.py)Your solution is correct in terms of functionality: it passes all the operations correctly. However, there are important considerations:
Here's a simple example of a better approach in Python: class MyHashSet:
def __init__(self):
self.size = 1000
self.buckets = [[] for _ in range(self.size)]
def _hash(self, key):
return key % self.size
def add(self, key):
bucket_index = self._hash(key)
bucket = self.buckets[bucket_index]
if key not in bucket:
bucket.append(key)
def remove(self, key):
bucket_index = self._hash(key)
bucket = self.buckets[bucket_index]
if key in bucket:
bucket.remove(key)
def contains(self, key):
bucket_index = self._hash(key)
bucket = self.buckets[bucket_index]
return key in bucketThis approach uses chaining to handle collisions. The time complexity for each operation is O(n) in the worst case for a bucket, but with a good hash function and enough buckets, it is efficient on average.
VERDICT: NEEDS_IMPROVEMENT Implement Min Stack (design-minstack.py)Note: The verdict should be based on whether the student's solution is correct and efficient enough to meet the problem requirements. Now, evaluate the student's solution. VERDICT: NEEDS_IMPROVEMENT |
No description provided.