forked from dubey-harshit/Hacktoberfest-2024
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLeetCode3307.cpp
More file actions
20 lines (20 loc) · 771 Bytes
/
LeetCode3307.cpp
File metadata and controls
20 lines (20 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Solution {
public:
char kthCharacter(long long k, vector<int>& operations) {
char ans = 'a';
long long p = k-1; //k-1 for indexing purposes
vector<int> s; //contains the binary vector of k-1
while(p > 0){ //creating the binary vector
s.push_back(p%2);
p = p/2;
}
// for(auto elem : s)cout << elem << " ";;
// cout << endl;
for(long long x = 0 ; x < s.size() ; x++){ //if you observe the character being updated, you can observe that for the required position if the binary digit is 1 then the operation happens else it doesn't
if(s[x] == 1){
if(operations[x] == 1)ans = (ans-'a'+1)%26 + 'a';
}
}
return ans;
}
};