Generate Bitonic Sequence of length N from integers in a given range | Java program for the above approach ; 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
import java . util . * ; class GFG { public static void bitonicSequence ( int num , int lower , int upper ) { if ( num > ( upper - lower ) * 2 + 1 ) { System . out . println ( - 1 ) ; return ; } Deque < Integer > ans = new ArrayDeque < > ( ) ; for ( int i = 0 ; i < Math . min ( upper - lower + 1 , num - 1 ) ; i ++ ) ans . add ( upper - i ) ; for ( int i = 0 ; i < num - ans . size ( ) ; i ++ ) ans . addFirst ( upper - i - 1 ) ; System . out . println ( ans ) ; } public static void main ( String [ ] args ) { int N = 5 , L = 3 , R = 10 ; bitonicSequence ( N , L , R ) ; } }