Stores the count
var count = 0 ; var maxi = - 2147483648 ; for ( var i = 0 ; i < n ; i ++ ) { if ( next_greater [ i ] - i > k && maxi < arr [ i ] ) { maxi = Math . max ( maxi , arr [ i ] ) ; count ++ ; } } return count ; }