Store string that are initially have formed lexicographically smallest 2 k length substring
INDENT temp_str = " " NEW_LINE for i in range ( 0 , ( zeroes_in_2k ) // 2 ) : NEW_LINE INDENT temp_str += '0' NEW_LINE DEDENT for i in range ( 0 , ( ones_in_2k ) ) : NEW_LINE INDENT temp_str += '1' NEW_LINE DEDENT for i in range ( 0 , ( zeroes_in_2k ) // 2 ) : NEW_LINE INDENT temp_str += '0' NEW_LINE DEDENT DEDENT