HACKEREARTH - a game on numbers

Please help me understand the question,
i am trying but i am not able to understand what the question want to say,
Link

The problem says, suppose you have an array of N elements.
F(i) is defined such that for an index j which is greater than i, A[i]<A[j] and
G(i) is just the opposite of F(i) i.e. for a index j greater than i, A[i]>A[j]
So for every index i from 1 to N. They are telling to find out G(F(i)) i.e. for example for i=1, find a j greater than i and A[i]<A[j]. Then suppose the answer is Y. Find G(Y).
As in the example given, for 3 the greater element for it is 7. Now for 7 the smallest element is 1. So ans=1

1 Like

Since the N==30000 --> O(N*N) would work
we can do it in O(N) using stack;



refer this article then
and in this problem we insert index of element instead of A[i];
https://www.hackerearth.com/submission/45489406/
1 Like