Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions october_2024/potd_19_10_2024.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*

class Solution {
public:
char findKthBit(int n, int k) {
int invertCount = 0;
int len = (1 << n) - 1; // Length of Sn is 2^n - 1

while (k > 1) {
// If k is in the middle, return based on inversion count
if (k == len / 2 + 1) {
return invertCount % 2 == 0 ? '1' : '0';
}

// If k is in the second half, invert and mirror
if (k > len / 2) {
k = len + 1 - k; // Mirror position
invertCount++; // Increment inversion count
}

len /= 2; // Reduce length for next iteration
}

// For the first position, return based on inversion count
return invertCount % 2 == 0 ? '0' : '1';
}
};

*/
Loading