Find the k | Function to find the Kth string in lexicographical order which consists of N - 2 xs and 2 ys ; Iterate for all possible positions of left most Y ; If i is the left most position of Y ; Put Y in their positions ; Driver code ; Function call
def kth_string ( n , k ) : NEW_LINE INDENT for i in range ( n - 2 , - 1 , - 1 ) : NEW_LINE INDENT if k <= ( n - i - 1 ) : NEW_LINE INDENT for j in range ( n ) : NEW_LINE INDENT if ( j == i or j == n - k ) : NEW_LINE INDENT print ( ' Y ' , end = " " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( ' X ' , end = " " ) NEW_LINE DEDENT DEDENT break NEW_LINE DEDENT k -= ( n - i - 1 ) NEW_LINE DEDENT DEDENT n = 5 NEW_LINE k = 7 NEW_LINE kth_string ( n , k ) NEW_LINE