algos
algos copied to clipboard
added nextGreaterElement.c
Fixes #732
By submitting this pull request I confirm I've read and complied with the below declarations.
- [X] I have read the Contribution guidelines and I am confident that my PR reflects them.
- [X] I have followed the coding guidelines for this project.
- [X] My code follows the skeleton code structure.
- [X] This pull request has a descriptive title. For example,
Added {Algorithm/DS name} [{Language}]
, notUpdate README.md
orAdded new code
. - [X] This pull request will be closed if I fail to update it even once in a continuous time span of 7 days.
- [X] This pull request shall only be reviewed and merged once the Travis build passes. No maintainer or supporter shall be obliged to review it before this condition is met.
- [X] I have mentioned the issue number correctly (with hyperlink) in this pull request description.
@darshanhande11 provide a short video or screenshot for your implementation
@iiitv/project-maintainers
Problem Statement
Given an array, print the Next Greater Element (NGE) for every element. The Next greater Element for an element x is the first greater element on the right side of x in array. Elements for which no greater element exist, consider next greater element as -1.
Examples:
- For any array, rightmost element always has next greater element as -1.
- For an array which is sorted in decreasing order, all elements have next greater element as -1.
- For the input array [4, 5, 2, 25}, the next greater elements for each element are as follows.
I have attached the output screenshots which explains the implementation.
@ishanksoni please review the PR
@ishanksoni Sir, I have added the time and space complexity as comment in the code. Please let me know if any changes are to be done.