Conversation
Create Queue using Stacks (queue-using-stacks.py)Strengths:
Areas for Improvement:
Suggested Improvement for def empty(self) -> bool:
return not self.inStack and not self.outStackThis change makes the method more efficient and aligns with the reference solution. Overall, the solution is excellent and only requires a minor improvement in the VERDICT: PASS Implement Hash Map (design-hashmap.py)Your solution has a good start with the use of chaining and dummy nodes for each bucket. However, there are some issues that need to be addressed:
To fix your solution:
Here is a corrected version of your code: class Node:
def __init__(self, key=-1, val=-1, next=None):
self.key = key
self.val = val
self.next = next
class MyHashMap:
def __init__(self):
self.map = [Node() for _ in range(1000)]
def hash(self, key):
return key % len(self.map)
def put(self, key, value):
index = self.hash(key)
cur = self.map[index]
while cur.next:
if cur.next.key == key:
cur.next.val = value
return
cur = cur.next
cur.next = Node(key, value)
def get(self, key):
index = self.hash(key)
cur = self.map[index]
while cur.next:
if cur.next.key == key:
return cur.next.val
cur = cur.next
return -1
def remove(self, key):
index = self.hash(key)
cur = self.map[index]
while cur.next:
if cur.next.key == key:
cur.next = cur.next.next
return
cur = cur.nextVERDICT: NEEDS_IMPROVEMENT |
No description provided.