Generate Bitonic Sequence of length N from integers in a given range | Function to construct bitonic sequence of length N from integers in the range [ L , R ] ; If sequence is not possible ; Store the resultant list ; If size of deque < n ; Add elements from start ; Print the stored in the list ; Driver Code ; Function Call
function bitonicSequence ( num , lower , upper ) { if ( num > ( upper - lower ) * 2 + 1 ) { document . write ( - 1 ) ; return ; } var ans = [ ] ; for ( var i = 0 ; i < Math . min ( upper - lower + 1 , num - 1 ) ; i ++ ) ans . push ( upper - i ) ; for ( var i = 0 ; i < num - ans . length ; i ++ ) { ans . splice ( 0 , 0 , upper - i - 1 ) } document . write ( ' ' ) ; ans . forEach ( element => { document . write ( " " + element ) ; } ) ; document . write ( ' ' + ' ' ) ; } var N = 5 , L = 3 , R = 10 ; bitonicSequence ( N , L , R ) ;