Lexicographically largest N | Function to find the lexicographically largest bitonic sequence of size N elements lies in the range [ low , high ] ; Store index of highest element ; If high_index > ( N - 1 ) / 2 , then remaining N / 2 elements cannot be placed in bitonic order ; If high_index <= 0 , then set high_index as 1 ; Stores the resultant sequence ; Store the high value ; Maintain strictly decreasing sequence from index high_index to 0 starting with temp ; Store the value and decrement the temp variable by 1 ; Maintain the strictly decreasing sequence from index high_index + 1 to N - 1 starting with high - 1 ; Store the value and decrement high by 1 ; Print the resultant sequence ; Driver Code ; Function Call
function LargestArray ( N , low , high ) { let high_index = N - ( high - low + 1 ) ; if ( high_index > ( N - 1 ) / 2 ) { document . write ( " " ) ; return ; } if ( high_index <= 0 ) high_index = 1 ; let A = [ ] ; let temp = high ; for ( let i = high_index ; i >= 0 ; i -- ) { A [ i ] = temp -- ; } high -= 1 ; for ( let i = high_index + 1 ; i < N ; i ++ ) A [ i ] = high -- ; for ( let i = 0 ; i < N ; i ++ ) { document . write ( A [ i ] + " " ) ; } } let N = 5 , low = 2 , high = 6 ; LargestArray ( N , low , high ) ;