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
def LargestArray ( N , low , high ) : NEW_LINE INDENT high_index = N - ( high - low + 1 ) NEW_LINE if ( high_index > ( N - 1 ) // 2 ) : NEW_LINE INDENT print ( " Not ▁ Possible " ) NEW_LINE return NEW_LINE DEDENT if ( high_index <= 0 ) : NEW_LINE INDENT high_index = 1 NEW_LINE DEDENT A = [ 0 ] * N NEW_LINE temp = high NEW_LINE for i in range ( high_index , - 1 , - 1 ) : NEW_LINE INDENT A [ i ] = temp NEW_LINE temp = temp - 1 NEW_LINE DEDENT high -= 1 NEW_LINE for i in range ( high_index + 1 , N ) : NEW_LINE INDENT A [ i ] = high NEW_LINE high = high - 1 NEW_LINE DEDENT for i in range ( N ) : NEW_LINE INDENT print ( A [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT N = 5 NEW_LINE low = 2 NEW_LINE high = 6 NEW_LINE LargestArray ( N , low , high ) NEW_LINE