We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 57152a5 commit 979c679Copy full SHA for 979c679
october_2024/potd_19_10_2024.cpp
@@ -0,0 +1,29 @@
1
+/*
2
+
3
+class Solution {
4
+public:
5
+ char findKthBit(int n, int k) {
6
+ int invertCount = 0;
7
+ int len = (1 << n) - 1; // Length of Sn is 2^n - 1
8
9
+ while (k > 1) {
10
+ // If k is in the middle, return based on inversion count
11
+ if (k == len / 2 + 1) {
12
+ return invertCount % 2 == 0 ? '1' : '0';
13
+ }
14
15
+ // If k is in the second half, invert and mirror
16
+ if (k > len / 2) {
17
+ k = len + 1 - k; // Mirror position
18
+ invertCount++; // Increment inversion count
19
20
21
+ len /= 2; // Reduce length for next iteration
22
23
24
+ // For the first position, return based on inversion count
25
+ return invertCount % 2 == 0 ? '0' : '1';
26
27
+};
28
29
+*/
0 commit comments