Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request for PyVerse 💡
Requesting to submit a pull request to the PyVerse repository.
Issue Title
Please enter the title of the issue related to your pull request.
Min Stack
Info about the Related Issue
What's the goal of the project?
Design a Data Structure MinStack that supports all the stack operations like push(), pop(), and an additional operation getMin() which should return minimum element from the MinStack. All these operations of MinStack must have a time complexity of O(1).
Name
Please mention your name.
Shuvojit Samanta
GitHub ID
Please mention your GitHub ID.
shuvojitss
Email ID
Please mention your email ID for further communication.
shuvojitsamanta15@gmail.com
Identify Yourself
Mention in which program you are contributing (e.g., WoB, GSSOC, SSOC, SWOC).
GSSOC
Closes
Enter the issue number that will be closed through this PR.
Closes: #993
Describe the Add-ons or Changes You've Made
Give a clear description of what you have added or modified.
Time Complexity Analysis
push(value)
:pop()
:self.mini
. Listpop()
for the last element in Python is O(1).top()
:getmin()
:self.mini
.Summary
Each operation in this
MinStack
implementation has a time complexity of O(1), making it efficient for stack operations with constant-time minimum retrieval.Type of Change
Select the type of change:
How Has This Been Tested?
Describe how your changes have been tested.
I have tested it in all python editors and its working. I am providing a sample input output to describe it.
Sample Input
stack.push(7)
stack.push(12)
stack.getMin()
stack.push(4)
stack.getMin()
stack.pop()
stack.getMin()
stack.push(6)
stack.getMin()
stack.pop()
stack.top()
Sample Output:
Element Pushed: 7
Element Pushed: 12
Minimum Element in the stack is: 7
Element Pushed: 4
Minimum Element in the stack is: 4
Element popped: 4
Minimum Element in the stack is: 7
Element Pushed: 6
Minimum Element in the stack is: 6
Element popped: 6
Top Most Element is: 12
Checklist
Please confirm the following: