feat: Add `MinStackUsingTwoStacks` new algorithm with Junit tests
- [x] I have read CONTRIBUTING.md.
- [x] This pull request is all my own work -- I have not plagiarized it.
- [x] All filenames are in PascalCase.
- [x] All functions and variable names follow Java naming conventions.
- [x] All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
- [x] All new code is formatted with
clang-format -i --style=file path/to/your/file.java
Codecov Report
Attention: Patch coverage is 84.61538% with 2 lines in your changes missing coverage. Please review.
Project coverage is 63.98%. Comparing base (
6682c7c) to head (cdc4952).
| Files with missing lines | Patch % | Lines |
|---|---|---|
| ...m/thealgorithms/stacks/MinStackUsingTwoStacks.java | 84.61% | 1 Missing and 1 partial :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## master #5758 +/- ##
============================================
+ Coverage 63.96% 63.98% +0.01%
- Complexity 4172 4178 +6
============================================
Files 583 584 +1
Lines 16320 16333 +13
Branches 3150 3151 +1
============================================
+ Hits 10439 10450 +11
- Misses 5456 5457 +1
- Partials 425 426 +1
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
This contribution looks like from leetcode. And according to rules, could you please provide any sources that describe that this is not from leetcode or similar resources.
The MinStackUsingTwoStacks algorithm is a widely known solution in data structures, frequently discussed in programming interviews and textbooks. It is not exclusive to LeetCode but is a classic problem in designing a stack that supports push(), pop(), and retrieving the minimum element in constant time using two stacks—one to store the elements and the other to track the minimum values. You can find similar implementations and discussions on several well-known platforms, such as GeeksforGeeks and Stack Overflow, as well as in books like Cracking the Coding Interview.
- Design and Implement Special Stack Data Structure | Added Space Optimized Version
- Stack Overflow: MinStack discussion
- Design a stack that supports getMin() in O(1) time and O(1) extra space
This problem is a common way to assess problem-solving skills and understanding of space-time trade-offs in interviews and is thus not tied to any single platform.