From 20ab5a78b9c96f950c0fb02fa5d707a8870410da Mon Sep 17 00:00:00 2001 From: Shakthi Nandana Date: Tue, 7 Apr 2026 22:39:48 -0400 Subject: [PATCH 1/2] problem 1 --- queue-using-stack.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 queue-using-stack.py diff --git a/queue-using-stack.py b/queue-using-stack.py new file mode 100644 index 00000000..d254e7bb --- /dev/null +++ b/queue-using-stack.py @@ -0,0 +1,40 @@ +# // Time Complexity : O(1) amortized +# // Space Complexity : O(n) +# // Did this code successfully run on Leetcode : Yes +# // Any problem you faced while coding this : NA + +class MyQueue(object): + def __init__(self): + self.stack_in =[] + self.stack_out=[] + + def push(self, x): + """ + :type x: int + :rtype: None + """ + self.stack_in.append(x) + + + def pop(self): + """ + :rtype: int + """ + self.peek() + return self.stack_out.pop() + + + def peek(self): + """ + :rtype: int + """ + if not self.stack_out: + while self.stack_in: + self.stack_out.append(self.stack_in.pop()) + return self.stack_out[-1] + + def empty(self): + """ + :rtype: bool + """ + return not bool( self.stack_in or self.stack_out) \ No newline at end of file From e388dc083882ab640a171de8bd6269b9e62c63a1 Mon Sep 17 00:00:00 2001 From: Shakthi Nandana Date: Tue, 7 Apr 2026 23:40:11 -0400 Subject: [PATCH 2/2] problem 2 --- hashmap.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 hashmap.py diff --git a/hashmap.py b/hashmap.py new file mode 100644 index 00000000..2ffa158d --- /dev/null +++ b/hashmap.py @@ -0,0 +1,64 @@ +# // Time Complexity : O(1) for put, get and remove +# // Space Complexity : O(n) +# // Did this code successfully run on Leetcode : Yes +# // Any problem you faced while coding this : NA + +class MyHashMap(object): + buckets = 1000 + bucket_size=1001 + + def __init__(self): + self.hashmap=[None] * self.buckets + + def hashfunc1(self,key): + return key % self.buckets + + def hashfunc2(self,key): + return key // self.buckets + + + def put(self, key, value): + """ + :type key: int + :type value: int + :rtype: None + """ + primary_bucket = self.hashfunc1(key) + secondary_index = self.hashfunc2(key) + if self.hashmap[primary_bucket] is None: + self.hashmap[primary_bucket] = [None] * self.bucket_size + + self.hashmap[primary_bucket][secondary_index] = value + + def get(self, key): + """ + :type key: int + :rtype: int + """ + primary_bucket = self.hashfunc1(key) + secondary_index = self.hashfunc2(key) + + if self.hashmap[primary_bucket] is not None: + if self.hashmap[primary_bucket][secondary_index] is not None: + return self.hashmap[primary_bucket][secondary_index] + + return -1 + + + def remove(self, key): + """ + :type key: int + :rtype: None + """ + primary_bucket = self.hashfunc1(key) + secondary_index = self.hashfunc2(key) + + if self.hashmap[primary_bucket] is not None: + self.hashmap[primary_bucket][secondary_index]=None + + +# Your MyHashMap object will be instantiated and called as such: +# obj = MyHashMap() +# obj.put(key,value) +# param_2 = obj.get(key) +# obj.remove(key) \ No newline at end of file