Amazon SDE 2 - K-th binary number
Anonymous User
551

(It's a modification of https://leetcode.com/problems/k-th-symbol-in-grammar/ )

Given a input string with only zero and one.

Let's say string is : "101"

On the first row we write a given input string. Now in every subsequent row, we look at the previous row and replace each occurrence of 0 with 01, and each occurrence of 1 with 10.
Given row N and index K, return the K-th indexed symbol in row N. (The values of K are 1-indexed.)

Input : s = "101", N = 4, K = 7
row 1 : 101
row 2 : 100110
row 3 : 100101101001
row 4 : 100101100110100110010110

Output : 1

Comments (1)