From 47a664d1e21d3cdb1fa73b7ad428ac32b54e9d04 Mon Sep 17 00:00:00 2001 From: YogeshPardeshi <31638743+YogeshPardeshi@users.noreply.github.com> Date: Fri, 22 May 2026 07:14:03 -0400 Subject: [PATCH 1/2] complete design2 --- MyQueue.java | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 MyQueue.java diff --git a/MyQueue.java b/MyQueue.java new file mode 100644 index 00000000..4f1280c5 --- /dev/null +++ b/MyQueue.java @@ -0,0 +1,32 @@ +class MyQueue { + Stack inSt; + Stack outSt; + + public MyQueue() { + this.inSt = new Stack<>(); + this.outSt = new Stack<>(); + } + + public void push(int x) { + inSt.push(x); + } + + public int pop() { + if(empty()) return -1; + peek(); + return outSt.pop(); + } + + public int peek() { + if(outSt.isEmpty()){ + while(!inSt.isEmpty()){ + outSt.push(inSt.pop()); + } + } + return outSt.peek(); + } + + public boolean empty() { + return inSt.isEmpty() && outSt.isEmpty(); + } +} From e2c7aa81065484262a562788ae4d37f507a0e25a Mon Sep 17 00:00:00 2001 From: YogeshPardeshi <31638743+YogeshPardeshi@users.noreply.github.com> Date: Fri, 22 May 2026 21:34:36 -0400 Subject: [PATCH 2/2] Create MyHashMap.java --- MyHashMap.java | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 MyHashMap.java diff --git a/MyHashMap.java b/MyHashMap.java new file mode 100644 index 00000000..6902fd27 --- /dev/null +++ b/MyHashMap.java @@ -0,0 +1,51 @@ +class MyHashMap { + int primaryBuckets; + int secondaryBuckets; + int[][] storage; + + public MyHashMap() { + this.primaryBuckets = 1000; + this.secondaryBuckets = 1000; + this.storage = new int[primaryBuckets][]; + } + + private int getPrimaryHash(int key){ + return key % primaryBuckets; + } + + private int getSecondaryHash(int key){ + return key / secondaryBuckets; + } + + public void put(int key, int value) { + int primaryIndex = getPrimaryHash(key); + if(storage[primaryIndex] == null){ + if(primaryIndex == 0){ + storage[primaryIndex] = new int[secondaryBuckets+1]; + }else{ + storage[primaryIndex] = new int[secondaryBuckets]; + } + Arrays.fill(storage[primaryIndex], -1); + } + int secondaryIndex = getSecondaryHash(key); + storage[primaryIndex][secondaryIndex] = value; + } + + public void remove(int key) { + int primaryIndex = getPrimaryHash(key); + if(storage[primaryIndex] == null){ + return; + } + int secondaryIndex = getSecondaryHash(key); + storage[primaryIndex][secondaryIndex] = -1; + } + + public int get(int key) { + int primaryIndex = getPrimaryHash(key); + if(storage[primaryIndex] == null){ + return -1; + } + int secondaryIndex = getSecondaryHash(key); + return storage[primaryIndex][secondaryIndex]; + } +}