From 3e8897735b1ec27cdfaceb26d97286a20e672d1b Mon Sep 17 00:00:00 2001 From: Suresh Date: Tue, 7 Apr 2026 21:30:36 +0530 Subject: [PATCH 1/3] Done Design-1 --- Sample.java | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/Sample.java b/Sample.java index 1739a9cb..9e0fdb2a 100644 --- a/Sample.java +++ b/Sample.java @@ -5,3 +5,37 @@ // Your code here along with comments explaining your approach +import java.util.Stack; + +class MinStack { + Stack mainStack; + Stack minStack; + + public MinStack() { + mainStack = new Stack<>(); + minStack = new Stack<>(); + } + + public void push(int val) { + mainStack.push(val); + if (minStack.isEmpty() || val <= minStack.peek()) + minStack.push(val); + } + + public void pop() { + int poppedValue = mainStack.pop(); + if (poppedValue == minStack.peek()) + minStack.pop(); + } + + public int top() { + return mainStack.peek(); + } + + public int getMin() { + return minStack.peek(); + } +} + + + \ No newline at end of file From 1c7ae9582060b8708dc9aed84c5d299ba647834e Mon Sep 17 00:00:00 2001 From: pavanbollam Date: Tue, 7 Apr 2026 21:42:17 +0530 Subject: [PATCH 2/3] Code cleanup --- Sample.java | 1 - 1 file changed, 1 deletion(-) diff --git a/Sample.java b/Sample.java index 9e0fdb2a..83ee408f 100644 --- a/Sample.java +++ b/Sample.java @@ -37,5 +37,4 @@ public int getMin() { } } - \ No newline at end of file From 3f575803f3780565bdaca069e770b03767b1ea8d Mon Sep 17 00:00:00 2001 From: pavanbollam Date: Tue, 7 Apr 2026 21:46:09 +0530 Subject: [PATCH 3/3] code cleanup --- Sample.java | 1 - 1 file changed, 1 deletion(-) diff --git a/Sample.java b/Sample.java index 83ee408f..a9fad47a 100644 --- a/Sample.java +++ b/Sample.java @@ -3,7 +3,6 @@ // Did this code successfully run on Leetcode : // Any problem you faced while coding this : - // Your code here along with comments explaining your approach import java.util.Stack;