From a7b1147d7184f0f4186fa9e1fd3e11799db546a3 Mon Sep 17 00:00:00 2001 From: Shakthi Nandana Date: Tue, 7 Apr 2026 23:00:48 -0400 Subject: [PATCH 1/3] problem 1 --- hashset.py | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 hashset.py diff --git a/hashset.py b/hashset.py new file mode 100644 index 00000000..c09d9e91 --- /dev/null +++ b/hashset.py @@ -0,0 +1,64 @@ +# // Time Complexity : add, remove and contains operations are O(1) +# // Space Complexity : O(buckets * bucket_size) maximum space used when all the buckets are filled +# // Did this code successfully run on Leetcode : Yes +# // Any problem you faced while coding this : NA + +class MyHashSet(object): + buckets = 1000 + bucket_size=1001 + + def __init__(self): + self.hashset=[None] * self.buckets + + def hashfunc1(self,key): + return key % self.buckets + + def hashfunc2(self,key): + return key // self.bucket_size + + def add(self, key): + """ + :type key: int + :rtype: None + """ + primary_bucket = self.hashfunc1(key) + secondary_index = self.hashfunc2(key) + if self.hashset[primary_bucket] is None: + self.hashset[primary_bucket] = [False] * self.bucket_size + + self.hashset[primary_bucket][secondary_index] = True + + + def remove(self, key): + """ + :type key: int + :rtype: None + """ + + primary_bucket = self.hashfunc1(key) + secondary_index = self.hashfunc2(key) + + if self.hashset[primary_bucket] is not None: + self.hashset[primary_bucket][secondary_index]=False + + + def contains(self, key): + """ + :type key: int + :rtype: bool + """ + primary_bucket = self.hashfunc1(key) + secondary_index = self.hashfunc2(key) + + if self.hashset[primary_bucket] is not None: + return self.hashset[primary_bucket][secondary_index] + + return False + + + +# Your MyHashSet object will be instantiated and called as such: +# obj = MyHashSet() +# obj.add(key) +# obj.remove(key) +# param_3 = obj.contains(key) \ No newline at end of file From 52379addabde715c5ca950db2bc7115a7d4c56fb Mon Sep 17 00:00:00 2001 From: Shakthi Nandana Date: Tue, 7 Apr 2026 23:20:29 -0400 Subject: [PATCH 2/3] problem 2 --- min-stack.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 min-stack.py diff --git a/min-stack.py b/min-stack.py new file mode 100644 index 00000000..04a1db8d --- /dev/null +++ b/min-stack.py @@ -0,0 +1,52 @@ +# // Time Complexity : all operations are O(1) +# // Space Complexity : O(n) +# // Did this code successfully run on Leetcode : Yes +# // Any problem you faced while coding this : NA + +class MinStack(object): + + def __init__(self): + self.stack=[] + self.minStack=[] + + def push(self, val): + """ + :type val: int + :rtype: None + """ + self.stack.append(val) + if not self.minStack: + self.minStack.append(val) + else: + self.minStack.append(min(val,self.minStack[-1])) + + + def pop(self): + """ + :rtype: None + """ + self.stack.pop() + self.minStack.pop() + + + def top(self): + """ + :rtype: int + """ + return self.stack[-1] + + + def getMin(self): + """ + :rtype: int + """ + return self.minStack[-1] + + + +# Your MinStack object will be instantiated and called as such: +# obj = MinStack() +# obj.push(val) +# obj.pop() +# param_3 = obj.top() +# param_4 = obj.getMin() \ No newline at end of file From a52e2c3804dd8c5fd876bbe920613b5d4cd41ce6 Mon Sep 17 00:00:00 2001 From: Shakthi Nandana Date: Tue, 7 Apr 2026 23:41:10 -0400 Subject: [PATCH 3/3] update --- hashset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hashset.py b/hashset.py index c09d9e91..9d99f182 100644 --- a/hashset.py +++ b/hashset.py @@ -14,7 +14,7 @@ def hashfunc1(self,key): return key % self.buckets def hashfunc2(self,key): - return key // self.bucket_size + return key // self.buckets def add(self, key): """