Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
How to solve this problem in quadratic complexity ?
For every subarray start at index i, keep finding new maximum values until a value larger than arr[i] is found.
Since the limits are high, you need a linear solution.
Use a stack to keep the values of the array sorted as you iterate the array from the end to the start.
Keep popping from the stack the elements in sorted order until a value larger than arr[i] is found, these are the ones that person i can see.