Skip to content

Commit c0cfe11

Browse files
authored
Create README.md
1 parent 4651715 commit c0cfe11

File tree

1 file changed

+38
-0
lines changed
  • 1545. Find Kth Bit in Nth Binary String

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# 1545. Find Kth Bit in Nth Binary String
2+
3+
Given two positive integers n and k, the binary string Sn is formed as follows:
4+
5+
S1 = "0"
6+
Si = Si - 1 + "1" + reverse(invert(Si - 1)) for i > 1
7+
Where + denotes the concatenation operation, reverse(x) returns the reversed string x, and invert(x) inverts all the bits in x (0 changes to 1 and 1 changes to 0).
8+
9+
For example, the first four strings in the above sequence are:
10+
11+
S1 = "0"
12+
S2 = "011"
13+
S3 = "0111001"
14+
S4 = "011100110110001"
15+
Return the kth bit in Sn. It is guaranteed that k is valid for the given n.
16+
17+
18+
19+
### Example 1:
20+
```
21+
Input: n = 3, k = 1
22+
Output: "0"
23+
Explanation: S3 is "0111001".
24+
The 1st bit is "0".
25+
```
26+
### Example 2:
27+
```
28+
Input: n = 4, k = 11
29+
Output: "1"
30+
Explanation: S4 is "011100110110001".
31+
The 11th bit is "1".
32+
```
33+
34+
### Constraints:
35+
```
36+
1 <= n <= 20
37+
1 <= k <= 2n - 1
38+
```

0 commit comments

Comments
 (0)