From f40622c1a03dac6bbc94c34af66b571b46467444 Mon Sep 17 00:00:00 2001 From: RITIKA CHAUBE Date: Wed, 3 Jun 2026 19:10:36 -0400 Subject: [PATCH 1/2] Done Design 1 --- design-1.py | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 design-1.py diff --git a/design-1.py b/design-1.py new file mode 100644 index 000000000..c6bbb3b6c --- /dev/null +++ b/design-1.py @@ -0,0 +1,68 @@ +#Time Complexity : The time complexity is O(1) for all the operations ie add, remove and contains +#Space Complexity : The space complexity is O(M + K*N) M is the initial buck K is the number +# of secondary bucket and N is number of primary bucket initialized +#Did this code successfully run on Leetcode : YES +#Any problem you faced while coding this : Faced error in some of the syntax and was confused in +# writing the space complexity + + +#Your code here along with comments explaining your approach + +class MyHashSet(object): + + def __init__(self): + self.initialBucket=1000 + self.secondaryBucket=1000 + self.storage=[None]*self.initialBucket + + def hashfunc1(self,key): + return key % self.initialBucket + + def hashfunc2(self,key): + return key // self.secondaryBucket + + def add(self, key): + """ + :type key: int + :rtype: None + """ + bucket=self.hashfunc1(key) + internalBucket=self.hashfunc2(key) + if self.storage[bucket]==None: + if bucket==0: + self.storage[bucket]=[False]*(self.secondaryBucket+1) + else: + self.storage[bucket]=[False]*self.secondaryBucket + self.storage[bucket][internalBucket]=True + + + def remove(self, key): + """ + :type key: int + :rtype: None + """ + bucket=self.hashfunc1(key) + internalBucket=self.hashfunc2(key) + if self.storage[bucket]==None: + return + self.storage[bucket][internalBucket]=False + + + def contains(self, key): + """ + :type key: int + :rtype: bool + """ + bucket=self.hashfunc1(key) + internalBucket=self.hashfunc2(key) + if self.storage[bucket]==None: + return False + return self.storage[bucket][internalBucket] + + + +# Your MyHashSet object will be instantiated and called as such: +# obj = MyHashSet() +# obj.add(key) +# obj.remove(key) +# param_3 = obj.contains(key) From ed50884890558618d1999d05dc8c80c2d635e957 Mon Sep 17 00:00:00 2001 From: RITIKA CHAUBE Date: Wed, 3 Jun 2026 21:01:04 -0400 Subject: [PATCH 2/2] Done Design 1 updated the 2nd problem --- designminheap.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 designminheap.py diff --git a/designminheap.py b/designminheap.py new file mode 100644 index 000000000..4d59cfa36 --- /dev/null +++ b/designminheap.py @@ -0,0 +1,52 @@ +#Time Complexity : The time complexity is O(1) for all the operations +#Space Complexity : The space complexity is O(N) where N is no of elements pushed in stack +#Did this code successfully run on Leetcode : YES + +class MinStack(object): + + def __init__(self): + self.st=[] + self.min=float('inf') + + def push(self, val): + """ + :type val: int + :rtype: None + """ + if val <= self.min: + self.st.append(self.min) + self.min = val + + self.st.append(val) + + def pop(self): + """ + :rtype: None + """ + if not self.st: + return + if self.st.pop() == self.min: + self.min = self.st.pop() + + + def top(self): + """ + :rtype: int + """ + return self.st[-1] if self.st else None + + + def getMin(self): + """ + :rtype: int + """ + return self.min + + + +# 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