Kth element in permutation of first N natural numbers having all even numbers placed before odd numbers in increasing order | Function to find the K - th element in the required permutation ; Stores the required permutation ; Insert all the even numbers less than or equal to N ; Now , insert all odd numbers less than or equal to N ; Print the Kth element ; Driver Code ; functions call
def findKthElement ( N , K ) : NEW_LINE INDENT v = [ ] NEW_LINE for i in range ( 1 , N + 1 ) : NEW_LINE INDENT if ( i % 2 == 0 ) : NEW_LINE INDENT v . append ( i ) NEW_LINE DEDENT DEDENT for i in range ( 1 , N + 1 ) : NEW_LINE INDENT if ( i % 2 != 0 ) : NEW_LINE INDENT v . append ( i ) NEW_LINE DEDENT DEDENT print ( v [ K - 1 ] ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT N = 10 NEW_LINE K = 3 NEW_LINE findKthElement ( N , K ) NEW_LINE DEDENT