From d4c30ce715e33c645d4f60ee0d99deea4688a69a Mon Sep 17 00:00:00 2001 From: sumanth <58482399+sumanth00100@users.noreply.github.com> Date: Wed, 8 Apr 2026 19:04:20 -0400 Subject: [PATCH 1/2] implemented hashmap and queue using stacks --- design-hashmap.java | 34 +++++++++++++++++++++++++++++++ implement-queue-using-stacks.java | 0 2 files changed, 34 insertions(+) create mode 100644 design-hashmap.java create mode 100644 implement-queue-using-stacks.java diff --git a/design-hashmap.java b/design-hashmap.java new file mode 100644 index 00000000..3dd6c92e --- /dev/null +++ b/design-hashmap.java @@ -0,0 +1,34 @@ +// Time Complexity : +// Space Complexity : +// Did this code successfully run on Leetcode : +// Any problem you faced while coding this : + +import java.util.Arrays; +class MyHashMap { + + int[] hashstorage = new int[1000001]; + + public MyHashMap() { + Arrays.fill(hashstorage, -1); + } + + public void put(int key, int value) { + hashstorage[key] = value; + } + + public int get(int key) { + return hashstorage[key]; + } + + public void remove(int key) { + hashstorage[key]=-1; + } +} + +/** + * Your MyHashMap object will be instantiated and called as such: + * MyHashMap obj = new MyHashMap(); + * obj.put(key,value); + * int param_2 = obj.get(key); + * obj.remove(key); + */ \ No newline at end of file diff --git a/implement-queue-using-stacks.java b/implement-queue-using-stacks.java new file mode 100644 index 00000000..e69de29b From 536390c433dbbf9d0c2b698dd540b27244dc073e Mon Sep 17 00:00:00 2001 From: sumanth <58482399+sumanth00100@users.noreply.github.com> Date: Wed, 8 Apr 2026 19:05:59 -0400 Subject: [PATCH 2/2] implemented hashmap and queue using stacks --- design-hashmap.java | 8 +++--- implement-queue-using-stacks.java | 45 +++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 4 deletions(-) diff --git a/design-hashmap.java b/design-hashmap.java index 3dd6c92e..a75a3b79 100644 --- a/design-hashmap.java +++ b/design-hashmap.java @@ -1,7 +1,7 @@ -// 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(n) +// Did this code successfully run on Leetcode :Yes +// Any problem you faced while coding this :No import java.util.Arrays; class MyHashMap { diff --git a/implement-queue-using-stacks.java b/implement-queue-using-stacks.java index e69de29b..48e59b7a 100644 --- a/implement-queue-using-stacks.java +++ b/implement-queue-using-stacks.java @@ -0,0 +1,45 @@ +// Time Complexity : O(1) +// Space Complexity : O(n) +// Did this code successfully run on Leetcode : Yes +// Any problem you faced while coding this :No + +import java.util.Stack; + +class MyQueue { + Stack in = new Stack<>(); + Stack out = new Stack<>(); + public MyQueue() { + + } + + public void push(int x) { + in.push(x); + } + + public int pop() { + peek(); + return out.pop(); + } + + public int peek() { + if(out.isEmpty()){ + while(!in.isEmpty()){ + out.push(in.pop()); + } + } + return out.peek(); + } + + public boolean empty() { + return out.isEmpty() && in.isEmpty(); + } +} + +/** + * Your MyQueue object will be instantiated and called as such: + * MyQueue obj = new MyQueue(); + * obj.push(x); + * int param_2 = obj.pop(); + * int param_3 = obj.peek(); + * boolean param_4 = obj.empty(); + */ \ No newline at end of file