Print indices in non | Function to print the order of array elements generating non - decreasing quotient after division by X ; Stores the quotient and the order ; Traverse the array ; Sort the vector ; Print the order ; Driver Code
function printOrder ( order , N , X ) { let vect = [ ] ; for ( let i = 0 ; i < N ; i ++ ) { if ( order [ i ] % X == 0 ) { vect . push ( [ order [ i ] / X , i + 1 ] ) ; } else { vect . push ( [ order [ i ] / X + 1 , i + 1 ] ) ; } } vect . sort ( function ( a , b ) { return a [ 0 ] - b [ 0 ] } ) ; for ( let i = 0 ; i < N ; i ++ ) { document . write ( vect [ i ] [ 1 ] + " " ) ; } document . write ( ) ; } let N = 3 , X = 3 ; let order = [ 2 , 7 , 4 ] ; printOrder ( order , N , X ) ;