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.