From 80b8828e2e0ad6b259f7dedc30953519ae5a6c39 Mon Sep 17 00:00:00 2001 From: sandy7907 <98723438+sandy7907@users.noreply.github.com> Date: Wed, 4 Feb 2026 22:29:46 -0500 Subject: [PATCH 1/6] Add files via upload S30 | FAANMG Problem #2 | design-hashset --- MyHashSet.java | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 MyHashSet.java diff --git a/MyHashSet.java b/MyHashSet.java new file mode 100644 index 00000000..f94981fe --- /dev/null +++ b/MyHashSet.java @@ -0,0 +1,52 @@ + +public class MyHashSet { + int primaryArraySize; + int secondaryArraySize; + + boolean[][] customHashArray; + + public MyHashSet() { + this.primaryArraySize = 1001; + this.secondaryArraySize = 1000; + this.customHashArray = new boolean[primaryArraySize][]; + } + + public int getPrimaryHashValue(int key) { + return key / primaryArraySize + 1; + } + + public int getSecondaryHashValue(int key) { + return key % secondaryArraySize; + } + + public void add(int key) { + + int primaryPos = getPrimaryHashValue(key); + int secondaryPos = getSecondaryHashValue(key); + + if(customHashArray[primaryPos] == null) { + customHashArray[primaryPos] = new boolean[secondaryArraySize]; + } + customHashArray[primaryPos][secondaryPos] = true; + } + + public void remove(int key) { + int primaryPos = getPrimaryHashValue(key); + int secondaryPos = getSecondaryHashValue(key); + if(customHashArray[primaryPos] != null) { + customHashArray[primaryPos][secondaryPos] = false; + } + + } + + public boolean contains(int key) { + int primaryPos = getPrimaryHashValue(key); + + if(customHashArray[primaryPos] == null) { + return false; + } + int secondaryPos = getSecondaryHashValue(key); + return customHashArray[primaryPos][secondaryPos]; + + } +} From f7ce8e0abf844d08ddf986c428b812d82eb08702 Mon Sep 17 00:00:00 2001 From: sandy7907 <98723438+sandy7907@users.noreply.github.com> Date: Thu, 5 Feb 2026 00:16:01 -0500 Subject: [PATCH 2/6] S30 | FAANMG Problem #4 | implement-queue-using-stacks --- MyQueue.java | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 MyQueue.java diff --git a/MyQueue.java b/MyQueue.java new file mode 100644 index 00000000..70f56f1b --- /dev/null +++ b/MyQueue.java @@ -0,0 +1,36 @@ +class MyQueue { + + Stack inStack; + Stack outStack; + + public MyQueue() { + inStack = new Stack<>(); + outStack = new Stack<>(); + } + + public void push(int x) { + inStack.push(x); + } + + public int pop() { + if(outStack.isEmpty()) { + while(!inStack.isEmpty()) { + outStack.push(inStack.pop()); + } + } + return outStack.pop(); + } + + public int peek() { + if(outStack.isEmpty()) { + while(!inStack.isEmpty()) { + outStack.push(inStack.pop()); + } + } + return outStack.peek(); + } + + public boolean empty() { + return inStack.isEmpty() && outStack.isEmpty(); + } +} From e26f356efcf6c69923f07974c70862bd6395bf81 Mon Sep 17 00:00:00 2001 From: sandy7907 <98723438+sandy7907@users.noreply.github.com> Date: Thu, 5 Feb 2026 00:20:36 -0500 Subject: [PATCH 3/6] S30 | FAANMG Problem #2 | design-hashset --- MyHashSet.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/MyHashSet.java b/MyHashSet.java index f94981fe..fc586c56 100644 --- a/MyHashSet.java +++ b/MyHashSet.java @@ -1,22 +1,22 @@ +class MyHashSet { -public class MyHashSet { - int primaryArraySize; + int primaryArraySize; int secondaryArraySize; boolean[][] customHashArray; public MyHashSet() { - this.primaryArraySize = 1001; + this.primaryArraySize = 1000; this.secondaryArraySize = 1000; this.customHashArray = new boolean[primaryArraySize][]; } public int getPrimaryHashValue(int key) { - return key / primaryArraySize + 1; + return key % primaryArraySize; } public int getSecondaryHashValue(int key) { - return key % secondaryArraySize; + return key / secondaryArraySize; } public void add(int key) { @@ -25,7 +25,11 @@ public void add(int key) { int secondaryPos = getSecondaryHashValue(key); if(customHashArray[primaryPos] == null) { - customHashArray[primaryPos] = new boolean[secondaryArraySize]; + if(primaryPos == 0 && secondaryPos == 1000) { + customHashArray[primaryPos] = new boolean[secondaryArraySize + 1]; + } else { + customHashArray[primaryPos] = new boolean[secondaryArraySize]; + } } customHashArray[primaryPos][secondaryPos] = true; } From ec72fc50634793c585ea87a77e03502c718b188f Mon Sep 17 00:00:00 2001 From: sandy7907 <98723438+sandy7907@users.noreply.github.com> Date: Thu, 5 Feb 2026 00:22:12 -0500 Subject: [PATCH 4/6] Update MyQueue.java --- MyQueue.java | 35 ----------------------------------- 1 file changed, 35 deletions(-) diff --git a/MyQueue.java b/MyQueue.java index 70f56f1b..8b137891 100644 --- a/MyQueue.java +++ b/MyQueue.java @@ -1,36 +1 @@ -class MyQueue { - Stack inStack; - Stack outStack; - - public MyQueue() { - inStack = new Stack<>(); - outStack = new Stack<>(); - } - - public void push(int x) { - inStack.push(x); - } - - public int pop() { - if(outStack.isEmpty()) { - while(!inStack.isEmpty()) { - outStack.push(inStack.pop()); - } - } - return outStack.pop(); - } - - public int peek() { - if(outStack.isEmpty()) { - while(!inStack.isEmpty()) { - outStack.push(inStack.pop()); - } - } - return outStack.peek(); - } - - public boolean empty() { - return inStack.isEmpty() && outStack.isEmpty(); - } -} From 5ee282aa5dae3baf2677a869fdec18326ea99f89 Mon Sep 17 00:00:00 2001 From: sandy7907 <98723438+sandy7907@users.noreply.github.com> Date: Sat, 7 Feb 2026 00:22:40 -0500 Subject: [PATCH 5/6] S30 FAANMG Problem #4 | Create Queue using Stack --- MyQueue.java | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/MyQueue.java b/MyQueue.java index 8b137891..435a8b8d 100644 --- a/MyQueue.java +++ b/MyQueue.java @@ -1 +1,39 @@ +import java.util.Stack; +class MyQueue { + + + Stack inStack; + Stack outStack; + + public MyQueue() { + inStack = new Stack<>(); + outStack = new Stack<>(); + } + + public void push(int x) { + inStack.push(x); + } + + public int pop() { + if(outStack.isEmpty()) { + while(!inStack.isEmpty()) { + outStack.push(inStack.pop()); + } + } + return outStack.pop(); + } + + public int peek() { + if(outStack.isEmpty()) { + while(!inStack.isEmpty()) { + outStack.push(inStack.pop()); + } + } + return outStack.peek(); + } + + public boolean empty() { + return inStack.isEmpty() && outStack.isEmpty(); + } +} From c7544780a1a792e8f8231221f71f68f50797cb1a Mon Sep 17 00:00:00 2001 From: sandy7907 Date: Sat, 7 Feb 2026 14:00:28 -0500 Subject: [PATCH 6/6] S30 FAANMG Problem #3 | Implement Min Stack --- MinStack.java | 34 ++++++++++++++++++++++++++++++++++ MyQueue.java | 39 --------------------------------------- 2 files changed, 34 insertions(+), 39 deletions(-) create mode 100644 MinStack.java delete mode 100644 MyQueue.java diff --git a/MinStack.java b/MinStack.java new file mode 100644 index 00000000..de032a88 --- /dev/null +++ b/MinStack.java @@ -0,0 +1,34 @@ +import java.util.Stack; + +class MinStack { + + Stack storageStack; + Stack minStack; + int min; + + public MinStack() { + storageStack = new Stack<>(); + minStack = new Stack<>(); + min = Integer.MAX_VALUE; + } + + public void push(int val) { + storageStack.push(val); + min = Math.min(min, val); + minStack.push(min); + } + + public void pop() { + storageStack.pop(); + minStack.pop(); + min = minStack.isEmpty() ? Integer.MAX_VALUE : minStack.peek(); + } + + public int top() { + return storageStack.peek(); + } + + public int getMin() { + return minStack.peek(); + } +} \ No newline at end of file diff --git a/MyQueue.java b/MyQueue.java deleted file mode 100644 index 435a8b8d..00000000 --- a/MyQueue.java +++ /dev/null @@ -1,39 +0,0 @@ -import java.util.Stack; - -class MyQueue { - - - Stack inStack; - Stack outStack; - - public MyQueue() { - inStack = new Stack<>(); - outStack = new Stack<>(); - } - - public void push(int x) { - inStack.push(x); - } - - public int pop() { - if(outStack.isEmpty()) { - while(!inStack.isEmpty()) { - outStack.push(inStack.pop()); - } - } - return outStack.pop(); - } - - public int peek() { - if(outStack.isEmpty()) { - while(!inStack.isEmpty()) { - outStack.push(inStack.pop()); - } - } - return outStack.peek(); - } - - public boolean empty() { - return inStack.isEmpty() && outStack.isEmpty(); - } -}