|
| 1 | +<p>You are given a string <code>s</code> and an integer <code>k</code>. Encrypt the string using the following algorithm:</p> |
| 2 | + |
| 3 | +<ul> |
| 4 | + <li>For each character <code>c</code> in <code>s</code>, replace <code>c</code> with the <code>k<sup>th</sup></code> character after <code>c</code> in the string (in a cyclic manner).</li> |
| 5 | +</ul> |
| 6 | + |
| 7 | +<p>Return the <em>encrypted string</em>.</p> |
| 8 | + |
| 9 | +<p> </p> |
| 10 | +<p><strong class="example">Example 1:</strong></p> |
| 11 | + |
| 12 | +<div class="example-block"> |
| 13 | +<p><strong>Input:</strong> <span class="example-io">s = "dart", k = 3</span></p> |
| 14 | + |
| 15 | +<p><strong>Output:</strong> <span class="example-io">"tdar"</span></p> |
| 16 | + |
| 17 | +<p><strong>Explanation:</strong></p> |
| 18 | + |
| 19 | +<ul> |
| 20 | + <li>For <code>i = 0</code>, the 3<sup>rd</sup> character after <code>'d'</code> is <code>'t'</code>.</li> |
| 21 | + <li>For <code>i = 1</code>, the 3<sup>rd</sup> character after <code>'a'</code> is <code>'d'</code>.</li> |
| 22 | + <li>For <code>i = 2</code>, the 3<sup>rd</sup> character after <code>'r'</code> is <code>'a'</code>.</li> |
| 23 | + <li>For <code>i = 3</code>, the 3<sup>rd</sup> character after <code>'t'</code> is <code>'r'</code>.</li> |
| 24 | +</ul> |
| 25 | +</div> |
| 26 | + |
| 27 | +<p><strong class="example">Example 2:</strong></p> |
| 28 | + |
| 29 | +<div class="example-block"> |
| 30 | +<p><strong>Input:</strong> <span class="example-io">s = "aaa", k = 1</span></p> |
| 31 | + |
| 32 | +<p><strong>Output:</strong> <span class="example-io">"aaa"</span></p> |
| 33 | + |
| 34 | +<p><strong>Explanation:</strong></p> |
| 35 | + |
| 36 | +<p>As all the characters are the same, the encrypted string will also be the same.</p> |
| 37 | +</div> |
| 38 | + |
| 39 | +<p> </p> |
| 40 | +<p><strong>Constraints:</strong></p> |
| 41 | + |
| 42 | +<ul> |
| 43 | + <li><code>1 <= s.length <= 100</code></li> |
| 44 | + <li><code>1 <= k <= 10<sup>4</sup></code></li> |
| 45 | + <li><code>s</code> consists only of lowercase English letters.</li> |
| 46 | +</ul> |
0 commit comments