Floor of every element in same array | Prints greater elements on left side of every element ; Create a sorted copy of arr [ ] ; Traverse through arr [ ] and do binary search for every element . ; Floor of first element is - 1 if there is only one occurrence of it . ; Find the first element that is greater than or or equal to given element ; If next element is also same , then there are multiple occurrences , so print it ; Otherwise print previous element ; Driver program to test insertion sort
function printPrevGreater ( arr , n ) { let v = [ ... arr ] v . sort ( ( a , b ) => a - b ) ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == v [ 0 ] ) { ( arr [ i ] == v [ 1 ] ) ? document . write ( arr [ i ] ) : document . write ( - 1 ) ; document . write ( " " ) ; continue ; } if ( v . includes ( arr [ i ] ) ) it = v [ v . indexOf ( arr [ i ] ) ] else it = v [ n - 1 ] if ( it != v [ n - 1 ] && ( v [ v . indexOf ( it ) + 1 ] == arr [ i ] ) ) document . write ( arr [ i ] + " " ) ; else document . write ( v [ v . indexOf ( it ) - 1 ] + " " ) ; } } function lower_bound ( arr , val ) { } let arr = [ 6 , 11 , 7 , 8 , 20 , 12 ] ; let n = arr . length ; printPrevGreater ( arr , n ) ;