For each element storing the index of just greater element in right side
right = nextGreaterInRight ( arr ) NEW_LINE ans = - 1 NEW_LINE for i in range ( 1 , len ( left ) - 1 ) : NEW_LINE INDENT if left [ i ] == 0 or right [ i ] == 0 : NEW_LINE DEDENT