Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
803 views
in Online Assessments by Expert (34,270 points) | 803 views

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 (34,270 points)