Next Smaller Element | prints element and NSE pair for all elements of arr [ ] of size n ; Driver Code
function printNSE ( arr , n ) { var next , i , j ; for ( i = 0 ; i < n ; i ++ ) { next = - 1 ; for ( j = i + 1 ; j < n ; j ++ ) { if ( arr [ i ] > arr [ j ] ) { next = arr [ j ] ; break ; } } document . write ( arr [ i ] + " " + next + " " ) ; } } var arr = [ 11 , 13 , 21 , 3 ] ; var n = arr . length ; printNSE ( arr , n ) ;