From 9a07fd21ae9ea758d3abe29a64baf7df7368d256 Mon Sep 17 00:00:00 2001 From: dhruvil15 <76967484+dhruvil15@users.noreply.github.com> Date: Tue, 7 Apr 2026 20:21:11 -0400 Subject: [PATCH 1/2] complete Desgin-1 --- .idea/.gitignore | 8 ++++++++ .idea/Design-1.iml | 9 +++++++++ .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ .idea/vcs.xml | 6 ++++++ Sample.java | 35 +++++++++++++++++++++++++++++++---- 6 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/Design-1.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..13566b81 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/Design-1.iml b/.idea/Design-1.iml new file mode 100644 index 00000000..d6ebd480 --- /dev/null +++ b/.idea/Design-1.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..639900d1 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..cc065d00 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Sample.java b/Sample.java index 1739a9cb..ee038383 100644 --- a/Sample.java +++ b/Sample.java @@ -1,7 +1,34 @@ -// Time Complexity : -// Space Complexity : -// Did this code successfully run on Leetcode : -// Any problem you faced while coding this : +// Time Complexity : O(1) +// Space Complexity : O(1) -> O(1000001) +// Did this code successfully run on Leetcode : Yes +// Any problem you faced while coding this : Initialized the boolean set with only 100 as the limit // Your code here along with comments explaining your approach +class MyHashSet { + boolean[] set; + + public MyHashSet() { + set = new boolean[1000001]; + } + + public void add(int key) { + set[key] = true; + } + + public void remove(int key) { + set[key] = false; + } + + public boolean contains(int key) { + return set[key]; + } +} + +/** + * Your MyHashSet object will be instantiated and called as such: + * MyHashSet obj = new MyHashSet(); + * obj.add(key); + * obj.remove(key); + * boolean param_3 = obj.contains(key); + */ \ No newline at end of file From f43e9c1985bb51c279ab663c2ce7a8fe5fd7fc1a Mon Sep 17 00:00:00 2001 From: dhruvil15 <76967484+dhruvil15@users.noreply.github.com> Date: Wed, 8 Apr 2026 20:08:45 -0400 Subject: [PATCH 2/2] complete Problem3 --- Problem3.java | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Problem3.java diff --git a/Problem3.java b/Problem3.java new file mode 100644 index 00000000..84e90062 --- /dev/null +++ b/Problem3.java @@ -0,0 +1,40 @@ +// Time Complexity: O(1) +// Space Complexity: O(N) + +class MinStack { + private ArrayList st; + + public MinStack() { + st = new ArrayList<>(); + } + + public void push(int val) { + int[] top = st.isEmpty() ? new int[]{val, val} : st.get(st.size() - 1); + int min_value = top[1]; + if (min_value > val) { + min_value = val; + } + st.add(new int[]{val, min_value}); + } + + public void pop() { + st.remove(st.size()-1); + } + + public int top() { + return st.isEmpty() ? -1 : st.get(st.size() - 1)[0]; + } + + public int getMin() { + return st.isEmpty() ? -1 : st.get(st.size() - 1)[1]; + } +} + +/** + * Your MinStack object will be instantiated and called as such: + * MinStack obj = new MinStack(); + * obj.push(val); + * obj.pop(); + * int param_3 = obj.top(); + * int param_4 = obj.getMin(); + */ \ No newline at end of file