Wrong answer : https://ide.codingblocks.com/s/170690

I tried to modify the query part accordingly so that for every node it will check whether the value is less than the maximum value in that range if yes then continue till the last node otherwise return 0.

At every node you have to store the sorted part of elements of that range, and then when you meet a range ,just do binary search and return the answer.

For better understanding , refer this -:

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.