-
Notifications
You must be signed in to change notification settings - Fork 20.4k
Description
What would you like to Propose?
Proposal: Add a new file containing a set of classic stack-based algorithms.
Algorithm Name and Problem Statement:
I propose adding a new file, NearestElement.java
, to the datastructures/stacks
package. This file will implement four closely related algorithms:
- Nearest Greater to Right: For each element in an array, find the first element to its right that is greater.
- Nearest Greater to Left: For each element in an array, find the first element to its left that is greater.
- Nearest Smaller to Right: For each element in an array, find the first element to its right that is smaller.
- Nearest Smaller to Left: For each element in an array, find the first element to its left that is smaller.
Justification:
These algorithms are a fundamental application of the Stack data structure. They are highly valuable for educational purposes and are common in technical interviews and for solving many popular LeetCode problems.
Hacktoberfest Contribution:
I would like to work on this for Hacktoberfest. I have read the CONTRIBUTING.md
guidelines and will ensure my submission includes a main
method for demonstration and a full suite of JUnit 5 tests.
Issue details
Is your feature request related to a problem? Please describe.
This request is to add a set of classic algorithms that are excellent demonstrations of the Stack data structure. These are frequently asked in technical interviews and would be a valuable addition to the library. They are also fundamental for solving many popular LeetCode problems involving arrays and stacks.
Describe the solution you'd like
I would like to add a new file, NearestElement.java
, inside the datastructures/stacks
package. This file will contain four static methods:
nearestGreaterToRight(int[] arr)
nearestGreaterToLeft(int[] arr)
nearestSmallerToRight(int[] arr)
nearestSmallerToLeft(int[] arr)
Additional context
I would like to work on this contribution for Hacktoberfest.
I have read the CONTRIBUTING.md
guidelines and will ensure my pull request includes:
- A class-level Javadoc explaining the algorithms.
- A
main
method insideNearestElement.java
for demonstration. - A corresponding
NearestElementTest.java
file with JUnit 5 tests.
Could you please assign this issue to me?
Additional Information
No response