From f542e0a308f0dd8f577427cb680157d901b9d897 Mon Sep 17 00:00:00 2001 From: spencerkrebs Date: Tue, 7 Apr 2026 20:25:42 -0400 Subject: [PATCH 1/3] 232 --- lc-232.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 lc-232.py diff --git a/lc-232.py b/lc-232.py new file mode 100644 index 00000000..ff7f1eb4 --- /dev/null +++ b/lc-232.py @@ -0,0 +1,39 @@ +# O(n) time +# O(n) space + +class MyQueue: + + def __init__(self): + self.inStack = [] # stores all newly pushed elements + self.outStack=[] # used for popping and peeking elements in fifo order + + def push(self, x: int) -> None: + self.inStack.append(x) + + def pop(self) -> int: + if not self.outStack: + while self.inStack: + self.outStack.append(self.inStack.pop()) + + return self.outStack.pop() + + def peek(self) -> int: + if not self.outStack: + while self.inStack: + self.outStack.append(self.inStack.pop()) + + return self.outStack[-1] + + def empty(self) -> bool: + if len(self.inStack)==0 and len(self.outStack)==0: + return True + else: + return False + + +# Your MyQueue object will be instantiated and called as such: +# obj = MyQueue() +# obj.push(x) +# param_2 = obj.pop() +# param_3 = obj.peek() +# param_4 = obj.empty() \ No newline at end of file From 08b236a2f1b5d2beb268d2ef4d668d444001d0c5 Mon Sep 17 00:00:00 2001 From: spencerkrebs Date: Sun, 12 Apr 2026 13:16:11 -0400 Subject: [PATCH 2/3] hashing --- design-hashmap.py | 45 ++++++++++++++++++++++++++++++ lc-232.py => queue-using-stacks.py | 0 2 files changed, 45 insertions(+) create mode 100644 design-hashmap.py rename lc-232.py => queue-using-stacks.py (100%) diff --git a/design-hashmap.py b/design-hashmap.py new file mode 100644 index 00000000..318ec5fa --- /dev/null +++ b/design-hashmap.py @@ -0,0 +1,45 @@ +class Node: + def __init__(self, key=-1,val=-1, next=None): + self.key=key + self.val=val + self.next = next + +class MyHashMap: +# key | value +# 100 | 1 +# 1100 | 2 +# 100 % 1000 = 100 +# 1100 %1000 = 100 +# key | value +# 100 | (100,1)->(1100,2) + def __init__(self): + self.map = [Node() for i in range(1000)] + + def hash(self,key): + return key % len(self.map) + + def put(self, key: int, value: int) -> None: + cur = self.map[self.hash(key)] + 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: int) -> int: + cur = self.map[self.hash(key)] + while cur: + if cur.key == key: + return cur.val + cur = cur.next + + return -1 + + def remove(self, key: int) -> None: + cur = self.map[self.hash(key)] + while cur and cur.next: + if cur.next.key == key: + cur.next = cur.next.next + return + cur = cur.next diff --git a/lc-232.py b/queue-using-stacks.py similarity index 100% rename from lc-232.py rename to queue-using-stacks.py From aeb7ae276e6f0c48efbb66014ce8ce7820289156 Mon Sep 17 00:00:00 2001 From: spencerkrebs Date: Sun, 12 Apr 2026 13:19:40 -0400 Subject: [PATCH 3/3] hashing --- design-hashmap.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/design-hashmap.py b/design-hashmap.py index 318ec5fa..80c2888c 100644 --- a/design-hashmap.py +++ b/design-hashmap.py @@ -1,3 +1,6 @@ +# time O(1) +# space O(n) + class Node: def __init__(self, key=-1,val=-1, next=None): self.key=key