Given an array A of size N Integers, where A[i] represent height of (i)th building. if someone is in the ith building he can move to the jth building if i<j && A[i]<A[j]. Given Q queries, In the ith query in the form of two array U and V. where Ui and Vi represents position of alice and bob on the array. Alice is on U[i]th building and Bob is on the B[i]th building. You have to return minimum building number K that both alice and bob can move to. if not possible return -1;
Testcase Input N=3; 1 3 2 Q=3; U = 1 3 2 V = 2 1 3
output 2 3 -1
I approched this problem with segment tree lazy propagation but couldnt work out. Any help would be appreciated!




