|
| 1 | +<p>Alice and Bob are playing a game. Initially, Alice has a string <code>word = "a"</code>.</p> |
| 2 | + |
| 3 | +<p>You are given a <strong>positive</strong> integer <code>k</code>. You are also given an integer array <code>operations</code>, where <code>operations[i]</code> represents the <strong>type</strong> of the <code>i<sup>th</sup></code> operation.</p> |
| 4 | + |
| 5 | +<p>Now Bob will ask Alice to perform <strong>all</strong> operations in sequence:</p> |
| 6 | + |
| 7 | +<ul> |
| 8 | + <li>If <code>operations[i] == 0</code>, <strong>append</strong> a copy of <code>word</code> to itself.</li> |
| 9 | + <li>If <code>operations[i] == 1</code>, generate a new string by <strong>changing</strong> each character in <code>word</code> to its <strong>next</strong> character in the English alphabet, and <strong>append</strong> it to the <em>original</em> <code>word</code>. For example, performing the operation on <code>"c"</code> generates <code>"cd"</code> and performing the operation on <code>"zb"</code> generates <code>"zbac"</code>.</li> |
| 10 | +</ul> |
| 11 | + |
| 12 | +<p>Return the value of the <code>k<sup>th</sup></code> character in <code>word</code> after performing all the operations.</p> |
| 13 | + |
| 14 | +<p><strong>Note</strong> that the character <code>'z'</code> can be changed to <code>'a'</code> in the second type of operation.</p> |
| 15 | + |
| 16 | +<p> </p> |
| 17 | +<p><strong class="example">Example 1:</strong></p> |
| 18 | + |
| 19 | +<div class="example-block"> |
| 20 | +<p><strong>Input:</strong> <span class="example-io">k = 5, operations = [0,0,0]</span></p> |
| 21 | + |
| 22 | +<p><strong>Output:</strong> <span class="example-io">"a"</span></p> |
| 23 | + |
| 24 | +<p><strong>Explanation:</strong></p> |
| 25 | + |
| 26 | +<p>Initially, <code>word == "a"</code>. Alice performs the three operations as follows:</p> |
| 27 | + |
| 28 | +<ul> |
| 29 | + <li>Appends <code>"a"</code> to <code>"a"</code>, <code>word</code> becomes <code>"aa"</code>.</li> |
| 30 | + <li>Appends <code>"aa"</code> to <code>"aa"</code>, <code>word</code> becomes <code>"aaaa"</code>.</li> |
| 31 | + <li>Appends <code>"aaaa"</code> to <code>"aaaa"</code>, <code>word</code> becomes <code>"aaaaaaaa"</code>.</li> |
| 32 | +</ul> |
| 33 | +</div> |
| 34 | + |
| 35 | +<p><strong class="example">Example 2:</strong></p> |
| 36 | + |
| 37 | +<div class="example-block"> |
| 38 | +<p><strong>Input:</strong> <span class="example-io">k = 10, operations = [0,1,0,1]</span></p> |
| 39 | + |
| 40 | +<p><strong>Output:</strong> <span class="example-io">"b"</span></p> |
| 41 | + |
| 42 | +<p><strong>Explanation:</strong></p> |
| 43 | + |
| 44 | +<p>Initially, <code>word == "a"</code>. Alice performs the four operations as follows:</p> |
| 45 | + |
| 46 | +<ul> |
| 47 | + <li>Appends <code>"a"</code> to <code>"a"</code>, <code>word</code> becomes <code>"aa"</code>.</li> |
| 48 | + <li>Appends <code>"bb"</code> to <code>"aa"</code>, <code>word</code> becomes <code>"aabb"</code>.</li> |
| 49 | + <li>Appends <code>"aabb"</code> to <code>"aabb"</code>, <code>word</code> becomes <code>"aabbaabb"</code>.</li> |
| 50 | + <li>Appends <code>"bbccbbcc"</code> to <code>"aabbaabb"</code>, <code>word</code> becomes <code>"aabbaabbbbccbbcc"</code>.</li> |
| 51 | +</ul> |
| 52 | +</div> |
| 53 | + |
| 54 | +<p> </p> |
| 55 | +<p><strong>Constraints:</strong></p> |
| 56 | + |
| 57 | +<ul> |
| 58 | + <li><code>1 <= k <= 10<sup>14</sup></code></li> |
| 59 | + <li><code>1 <= operations.length <= 100</code></li> |
| 60 | + <li><code>operations[i]</code> is either 0 or 1.</li> |
| 61 | + <li>The input is generated such that <code>word</code> has <strong>at least</strong> <code>k</code> characters after all operations.</li> |
| 62 | +</ul> |
0 commit comments