Get best answers to any doubt/query/question related to programming , jobs, gate, internships and tech-companies. Feel free to ask a question and you will receive the best advice/suggestion related to anything you ask about software-engineering , development and programming problems .

0 like 0 dislike

1 Answer

0 like 0 dislike
You are given an array A of size N and an integer X
For each integer Ai ,find the value of the second next greater element by X to the right.
Constraints
1 <= N <= 10^5
1<= X <= 10^9;
Sample input
7 2
1 2 3 4 7 6 7
Output
4 7 6 6 -1 -1 -1

 

I was able to write the O(N^2) solution but not able to write better one.
by Expert (32,020 points)
...