Skip to content

fixed typos in NextGraterElement.java #4976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fixed typos in NextGraterElement.java
  • Loading branch information
ImmaculateShaba committed Dec 6, 2023
commit 93c2c0ffd311ced147a925dc27a15ad2bbdfa7b4
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
import java.util.Stack;

/*
Given an array "input" you need to print the first grater element for each element.
For a given element x of an array, the Next Grater element of that element is the
first grater element to the right side of it. If no such element is present print -1.
Given an array "input" you need to print the first greater element for each element.
For a given element x of an array, the Next greater element of that element is the
first greater element to the right side of it. If no such element is present print -1.

Example
input = { 2, 7, 3, 5, 4, 6, 8 };
At i = 0
Next Grater element between (1 to n) is 7
Next greater element between (1 to n) is 7
At i = 1
Next Grater element between (2 to n) is 8
Next greater element between (2 to n) is 8
At i = 2
Next Grater element between (3 to n) is 5
Next greater element between (3 to n) is 5
At i = 3
Next Grater element between (4 to n) is 6
Next greater element between (4 to n) is 6
At i = 4
Next Grater element between (5 to n) is 6
Next greater element between (5 to n) is 6
At i = 5
Next Grater element between (6 to n) is 8
Next greater element between (6 to n) is 8
At i = 6
Next Grater element between (6 to n) is -1
Next greater element between (6 to n) is -1

result : [7, 8, 5, 6, 6, 8, -1]

Expand All @@ -37,11 +37,11 @@ Next Grater element between (6 to n) is -1
popped elements.
d. Finally, push the next in the stack.

3. If elements are left in stack after completing while loop then their Next Grater element is
3. If elements are left in stack after completing while loop then their Next greater element is
-1.
*/

public class NextGraterElement {
public class NextGreaterElement {

public static int[] findNextGreaterElements(int[] array) {
if (array == null) {
Expand Down