3307.js
/** ------------------------------------------------------------------------------
*
* 3307. Find the K-th Character in String Game II
* Topics: Bit Manipulation
* https://leetcode.com/problems/find-the-k-th-character-in-string-game-ii/description/?envType=daily-question&envId=2025-07-04
*
------------------------------------------------------------------------------ */
var kthCharacter = function (k, operations) {
let ans = 0
while (k !== 1) {
let t = Math.floor(Math.log2(k))
if (Number(1n << BigInt(t)) === k) {
t--
}
k -= Number(1n << BigInt(t))
if (operations[t]) {
ans++
}
}
return String.fromCharCode("a".charCodeAt(0) + (ans % 26))
}
console.log(kthCharacter(5, [0, 0, 0]))