Skip to content

Commit 223dbe0

Browse files
committed
Create README - LeetHub
1 parent 0bdad03 commit 223dbe0

File tree

1 file changed

+63
-0
lines changed
  • 1747-lexicographically-smallest-string-after-applying-operations

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<h2><a href="https://leetcode.com/problems/lexicographically-smallest-string-after-applying-operations">1747. Lexicographically Smallest String After Applying Operations</a></h2><h3>Medium</h3><hr><p>You are given a string <code>s</code> of <strong>even length</strong> consisting of digits from <code>0</code> to <code>9</code>, and two integers <code>a</code> and <code>b</code>.</p>
2+
3+
<p>You can apply either of the following two operations any number of times and in any order on <code>s</code>:</p>
4+
5+
<ul>
6+
<li>Add <code>a</code> to all odd indices of <code>s</code> <strong>(0-indexed)</strong>. Digits post <code>9</code> are cycled back to <code>0</code>. For example, if <code>s = &quot;3456&quot;</code> and <code>a = 5</code>, <code>s</code> becomes <code>&quot;3951&quot;</code>.</li>
7+
<li>Rotate <code>s</code> to the right by <code>b</code> positions. For example, if <code>s = &quot;3456&quot;</code> and <code>b = 1</code>, <code>s</code> becomes <code>&quot;6345&quot;</code>.</li>
8+
</ul>
9+
10+
<p>Return <em>the <strong>lexicographically smallest</strong> string you can obtain by applying the above operations any number of times on</em> <code>s</code>.</p>
11+
12+
<p>A string <code>a</code> is lexicographically smaller than a string <code>b</code> (of the same length) if in the first position where <code>a</code> and <code>b</code> differ, string <code>a</code> has a letter that appears earlier in the alphabet than the corresponding letter in <code>b</code>. For example, <code>&quot;0158&quot;</code> is lexicographically smaller than <code>&quot;0190&quot;</code> because the first position they differ is at the third letter, and <code>&#39;5&#39;</code> comes before <code>&#39;9&#39;</code>.</p>
13+
14+
<p>&nbsp;</p>
15+
<p><strong class="example">Example 1:</strong></p>
16+
17+
<pre>
18+
<strong>Input:</strong> s = &quot;5525&quot;, a = 9, b = 2
19+
<strong>Output:</strong> &quot;2050&quot;
20+
<strong>Explanation:</strong> We can apply the following operations:
21+
Start: &quot;5525&quot;
22+
Rotate: &quot;2555&quot;
23+
Add: &quot;2454&quot;
24+
Add: &quot;2353&quot;
25+
Rotate: &quot;5323&quot;
26+
Add: &quot;5222&quot;
27+
Add: &quot;5121&quot;
28+
Rotate: &quot;2151&quot;
29+
Add: &quot;2050&quot;​​​​​
30+
There is no way to obtain a string that is lexicographically smaller than &quot;2050&quot;.
31+
</pre>
32+
33+
<p><strong class="example">Example 2:</strong></p>
34+
35+
<pre>
36+
<strong>Input:</strong> s = &quot;74&quot;, a = 5, b = 1
37+
<strong>Output:</strong> &quot;24&quot;
38+
<strong>Explanation:</strong> We can apply the following operations:
39+
Start: &quot;74&quot;
40+
Rotate: &quot;47&quot;
41+
​​​​​​​Add: &quot;42&quot;
42+
​​​​​​​Rotate: &quot;24&quot;​​​​​​​​​​​​
43+
There is no way to obtain a string that is lexicographically smaller than &quot;24&quot;.
44+
</pre>
45+
46+
<p><strong class="example">Example 3:</strong></p>
47+
48+
<pre>
49+
<strong>Input:</strong> s = &quot;0011&quot;, a = 4, b = 2
50+
<strong>Output:</strong> &quot;0011&quot;
51+
<strong>Explanation:</strong> There are no sequence of operations that will give us a lexicographically smaller string than &quot;0011&quot;.
52+
</pre>
53+
54+
<p>&nbsp;</p>
55+
<p><strong>Constraints:</strong></p>
56+
57+
<ul>
58+
<li><code>2 &lt;= s.length &lt;= 100</code></li>
59+
<li><code>s.length</code> is even.</li>
60+
<li><code>s</code> consists of digits from <code>0</code> to <code>9</code> only.</li>
61+
<li><code>1 &lt;= a &lt;= 9</code></li>
62+
<li><code>1 &lt;= b &lt;= s.length - 1</code></li>
63+
</ul>

0 commit comments

Comments
 (0)