Stores the count
count = 0 NEW_LINE maxi = - sys . maxsize - 1 NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( next_greater [ i ] - i > k and maxi < arr [ i ] ) : NEW_LINE INDENT maxi = max ( maxi , arr [ i ] ) NEW_LINE count += 1 NEW_LINE DEDENT DEDENT return count NEW_LINE