Trains the technique from
LeetCode 1545Find Kth Bit in Nth Binary StringThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A strip of paper is folded over and over, and after each pass the machine prints the creases it can feel as a row of 0 and 1 symbols.
Write P(1) = "0". Every later pass builds its row from the previous one:
P(i) = P(i - 1) + "1" + swap(reverse(P(i - 1)))
Here reverse reads a row from back to front and swap turns each 0 into a 1 and each 1 into a 0. So P(2) is "011" and P(3) is "0111001", and in general P(n) holds 2^n - 1 symbols.
Given the pass number n and a 1-indexed position k, return the symbol standing at position k of P(n) as a string of length one.
Example 1
P(3) is `0111001`, and its fifth symbol is `0`.
Example 2
P(2) is `011` and the third symbol is `1`.
Example 3
P(4) is `011100110110001`, whose eleventh symbol is `1`.
Example 4
The very first row holds the single symbol `0`.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def crease_at(passes: int, slot: int) -> str:public char creaseAt(int passes, int slot)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.