Generate Bitonic Sequence of length N from integers in a given range | Python3 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
from collections import deque NEW_LINE def bitonicSequence ( num , lower , upper ) : NEW_LINE INDENT if ( num > ( upper - lower ) * 2 + 1 ) : NEW_LINE INDENT print ( - 1 ) NEW_LINE return NEW_LINE DEDENT ans = deque ( ) NEW_LINE for i in range ( min ( upper - lower + 1 , num - 1 ) ) : NEW_LINE INDENT ans . append ( upper - i ) NEW_LINE DEDENT for i in range ( num - len ( ans ) ) : NEW_LINE INDENT ans . appendleft ( upper - i - 1 ) NEW_LINE DEDENT print ( list ( ans ) ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT N = 5 NEW_LINE L = 3 NEW_LINE R = 10 NEW_LINE bitonicSequence ( N , L , R ) NEW_LINE DEDENT