package leetcode;

/**
 * https://leetcode.com/problems/find-kth-bit-in-nth-binary-string/
 */
public class Problem1545 {
    public char findKthBit(int n, int k) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1545 prob = new Problem1545();
        System.out.println(prob.findKthBit(3, 1)); // "0"
        System.out.println(prob.findKthBit(4, 11)); // "1"
        System.out.println(prob.findKthBit(1, 1)); // "0"
        System.out.println(prob.findKthBit(2, 3)); // "1"
    }
}

@@ -170,32 +170,531 @@
     
-// TODO%0A        return 0
+String s = %220%22;%0A        for (int i = 0; i %3C n - 1; i++) %7B%0A            s = s + %221%22 + reverse(inverse(s));%0A            if (s.length() %3E= k) %7B%0A                return s.charAt(k - 1);%0A            %7D%0A        %7D%0A        return '0';%0A    %7D%0A%0A    private static String reverse(String s) %7B%0A        return new StringBuilder(s).reverse().toString();%0A    %7D%0A%0A    private static String inverse(String s) %7B%0A        String str = %22%22;%0A        for (char c : s.toCharArray()) %7B%0A            str += c == '0' ? '1' : '0';%0A        %7D%0A        return str
 ;%0A  
@@ -956,32 +956,32 @@
 (1, 1)); // %220%22%0A
-
         System.o
@@ -1018,20 +1018,85 @@
 3)); // %221%22%0A
+        System.out.println(prob.findKthBit(20, 1048575)); // %221%22%0A
     %7D%0A%7D%0A

Update problem 1545