Given an array, find 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 the array. Elements for which no greater element exist, consider the next greater element as -1.

AnswerBot
1y

Next greater element is a problem where we find the closest greater element for each element in an array.

  • Iterate through the array

  • For each element, compare it with the elements on its right

  • Find the fi...read more

2K19/EC/082 JATIN
2y

vector<long long> nextLargerElement(vector<long long> arr, int n){

// Your code here

long long ma=arr[n-1];

for(int i=n-1;i>=0;i--)

{

if(arr[i]>=ma)

{

ma=arr[i];

arr[i]=-1;

}

else

arr[i]=ma...read more

Help your peers!
Select
Add answer anonymously...

Jubilant Foods Works Software Engineer interview questions & answers

A Software Engineer was asked Q. Given a binary tree, return the zigzag level order traversal of its nodes' value...read more
A Software Engineer was asked Q. Given an array, find the next greater element (NGE) for every element. The Next ...read more
A Software Engineer was asked Q. Write a program to find all prime numbers up to a given number N.

Popular interview questions of Software Engineer

A Software Engineer was asked Q1. Given a binary tree, return the zigzag level order traversal of its nodes' value...read more
A Software Engineer was asked Q2. Given an array, find the next greater element (NGE) for every element. The Next ...read more
A Software Engineer was asked Q3. Write a program to find all prime numbers up to a given number N.
Jubilant Foods Works Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits