|
| 1 | +<p>You are given a string <code>s</code> and an integer <code>t</code>, representing the number of <strong>transformations</strong> to perform. In one <strong>transformation</strong>, every character in <code>s</code> is replaced according to the following rules:</p> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li>If the character is <code>'z'</code>, replace it with the string <code>"ab"</code>.</li> |
| 5 | + <li>Otherwise, replace it with the <strong>next</strong> character in the alphabet. For example, <code>'a'</code> is replaced with <code>'b'</code>, <code>'b'</code> is replaced with <code>'c'</code>, and so on.</li> |
| 6 | +</ul> |
| 7 | + |
| 8 | +<p>Return the <strong>length</strong> of the resulting string after <strong>exactly</strong> <code>t</code> transformations.</p> |
| 9 | + |
| 10 | +<p>Since the answer may be very large, return it <strong>modulo</strong><!-- notionvc: eb142f2b-b818-4064-8be5-e5a36b07557a --> <code>10<sup>9</sup> + 7</code>.</p> |
| 11 | + |
| 12 | +<p> </p> |
| 13 | +<p><strong class="example">Example 1:</strong></p> |
| 14 | + |
| 15 | +<div class="example-block"> |
| 16 | +<p><strong>Input:</strong> <span class="example-io">s = "abcyy", t = 2</span></p> |
| 17 | + |
| 18 | +<p><strong>Output:</strong> <span class="example-io">7</span></p> |
| 19 | + |
| 20 | +<p><strong>Explanation:</strong></p> |
| 21 | + |
| 22 | +<ul> |
| 23 | + <li><strong>First Transformation (t = 1)</strong>: |
| 24 | + |
| 25 | + <ul> |
| 26 | + <li><code>'a'</code> becomes <code>'b'</code></li> |
| 27 | + <li><code>'b'</code> becomes <code>'c'</code></li> |
| 28 | + <li><code>'c'</code> becomes <code>'d'</code></li> |
| 29 | + <li><code>'y'</code> becomes <code>'z'</code></li> |
| 30 | + <li><code>'y'</code> becomes <code>'z'</code></li> |
| 31 | + <li>String after the first transformation: <code>"bcdzz"</code></li> |
| 32 | + </ul> |
| 33 | + </li> |
| 34 | + <li><strong>Second Transformation (t = 2)</strong>: |
| 35 | + <ul> |
| 36 | + <li><code>'b'</code> becomes <code>'c'</code></li> |
| 37 | + <li><code>'c'</code> becomes <code>'d'</code></li> |
| 38 | + <li><code>'d'</code> becomes <code>'e'</code></li> |
| 39 | + <li><code>'z'</code> becomes <code>"ab"</code></li> |
| 40 | + <li><code>'z'</code> becomes <code>"ab"</code></li> |
| 41 | + <li>String after the second transformation: <code>"cdeabab"</code></li> |
| 42 | + </ul> |
| 43 | + </li> |
| 44 | + <li><strong>Final Length of the string</strong>: The string is <code>"cdeabab"</code>, which has 7 characters.</li> |
| 45 | +</ul> |
| 46 | +</div> |
| 47 | + |
| 48 | +<p><strong class="example">Example 2:</strong></p> |
| 49 | + |
| 50 | +<div class="example-block"> |
| 51 | +<p><strong>Input:</strong> <span class="example-io">s = "azbk", t = 1</span></p> |
| 52 | + |
| 53 | +<p><strong>Output:</strong> <span class="example-io">5</span></p> |
| 54 | + |
| 55 | +<p><strong>Explanation:</strong></p> |
| 56 | + |
| 57 | +<ul> |
| 58 | + <li><strong>First Transformation (t = 1)</strong>: |
| 59 | + |
| 60 | + <ul> |
| 61 | + <li><code>'a'</code> becomes <code>'b'</code></li> |
| 62 | + <li><code>'z'</code> becomes <code>"ab"</code></li> |
| 63 | + <li><code>'b'</code> becomes <code>'c'</code></li> |
| 64 | + <li><code>'k'</code> becomes <code>'l'</code></li> |
| 65 | + <li>String after the first transformation: <code>"babcl"</code></li> |
| 66 | + </ul> |
| 67 | + </li> |
| 68 | + <li><strong>Final Length of the string</strong>: The string is <code>"babcl"</code>, which has 5 characters.</li> |
| 69 | +</ul> |
| 70 | +</div> |
| 71 | + |
| 72 | +<p> </p> |
| 73 | +<p><strong>Constraints:</strong></p> |
| 74 | + |
| 75 | +<ul> |
| 76 | + <li><code>1 <= s.length <= 10<sup>5</sup></code></li> |
| 77 | + <li><code>s</code> consists only of lowercase English letters.</li> |
| 78 | + <li><code>1 <= t <= 10<sup>5</sup></code></li> |
| 79 | +</ul> |
0 commit comments