Initially, a string s contains only one character:
s = "a"
You are given a vector ops containing only 0 and 1. For every operation, the current string is transformed and appended to itself.
There are two types of operations:
Duplicate the current string and append the duplicate unchanged to the end.
For example:
s = "abc"
After operation 0:
s = "abcabc"
Duplicate the current string, increment every character in the duplicate by 1, and append it to the original string.
Characters are incremented cyclically:
a → b
b → c
...
y → z
z → a
For example:
s = "abc"
After operation 1:
s = "abcbcd"
You are given:
ops containing the operations to perform.k representing a 1-indexed position in the final string.After performing all operations in , return the character present at position .
opskN, the number of operations.N integers, where each integer is either 0 or 1.k.Print the character at the k-th position of the final string.
3
0 1 0
5
Initially:
"a"
After operation 0:
"aa"
After operation 1:
"abb"
After operation 0:
"abbabb"
The 5th character is:
b
b
2
1 1
4
Initially:
"a"
After operation 1:
"ab"
After operation 1:
"abbc"
The 4th character is:
c
c
1 ≤ N ≤ 10^5ops[i] ∈ {0, 1}1 ≤ k ≤ 2^NTeradata • Pending