algos icon indicating copy to clipboard operation
algos copied to clipboard

added nextGreaterElement.c

Open darshanhande11 opened this issue 3 years ago • 4 comments

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}], not Update README.md or Added 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 avatar Sep 03 '20 13:09 darshanhande11

@darshanhande11 provide a short video or screenshot for your implementation

theyashshahs avatar Sep 23 '20 09:09 theyashshahs

@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:

  1. For any array, rightmost element always has next greater element as -1.
  2. For an array which is sorted in decreasing order, all elements have next greater element as -1.
  3. 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.

image

image

darshanhande11 avatar Sep 29 '20 11:09 darshanhande11

@ishanksoni please review the PR

theyashshahs avatar Sep 29 '20 17:09 theyashshahs

@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.

darshanhande11 avatar Sep 30 '20 03:09 darshanhande11