Class Solution
java.lang.Object
g1601_1700.s1625_lexicographically_smallest_string_after_applying_operations.Solution
1625 - Lexicographically Smallest String After Applying Operations.<p>Medium</p>
<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>
<p>You can apply either of the following two operations any number of times and in any order on <code>s</code>:</p>
<ul>
<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 = "3456"</code> and <code>a = 5</code>, <code>s</code> becomes <code>"3951"</code>.</li>
<li>Rotate <code>s</code> to the right by <code>b</code> positions. For example, if <code>s = "3456"</code> and <code>b = 1</code>, <code>s</code> becomes <code>"6345"</code>.</li>
</ul>
<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>
<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>"0158"</code> is lexicographically smaller than <code>"0190"</code> because the first position they differ is at the third letter, and <code>'5'</code> comes before <code>'9'</code>.</p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> s = “5525”, a = 9, b = 2</p>
<p><strong>Output:</strong> “2050”</p>
<p><strong>Explanation:</strong> We can apply the following operations:</p>
<p>Start: “5525”</p>
<p>Rotate: “2555”</p>
<p>Add: “2454”</p>
<p>Add: “2353”</p>
<p>Rotate: “5323”</p>
<p>Add: “5222”</p>
<p>Add: “5121”</p>
<p>Rotate: “2151”</p>
<p>Add: “2050”</p>
<p>There is no way to obtain a string that is lexicographically smaller then “2050”.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s = “74”, a = 5, b = 1</p>
<p><strong>Output:</strong> “24”</p>
<p><strong>Explanation:</strong> We can apply the following operations:</p>
<p>Start: “74”</p>
<p>Rotate: “47”</p>
<p>Add: “42”</p>
<p>Rotate: “24”</p>
<p>There is no way to obtain a string that is lexicographically smaller then “24”.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> s = “0011”, a = 4, b = 2</p>
<p><strong>Output:</strong> “0011”</p>
<p><strong>Explanation:</strong> There are no sequence of operations that will give us a lexicographically smaller string than “0011”.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 <= s.length <= 100</code></li>
<li><code>s.length</code> is even.</li>
<li><code>s</code> consists of digits from <code>0</code> to <code>9</code> only.</li>
<li><code>1 <= a <= 9</code></li>
<li><code>1 <= b <= s.length - 1</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
findLexSmallestString
-