java.lang.Object
g1501_1600.s1505_minimum_possible_integer_after_at_most_k_adjacent_swaps_on_digits.Solution

public class Solution extends Object
1505 - Minimum Possible Integer After at Most K Adjacent Swaps On Digits.<p>Hard</p> <p>You are given a string <code>num</code> representing <strong>the digits</strong> of a very large integer and an integer <code>k</code>. You are allowed to swap any two adjacent digits of the integer <strong>at most</strong> <code>k</code> times.</p> <p>Return <em>the minimum integer you can obtain also as a string</em>.</p> <p><strong>Example 1:</strong></p> <p><img src="https://assets.leetcode.com/uploads/2020/06/17/q4_1.jpg" alt="" /></p> <p><strong>Input:</strong> num = &ldquo;4321&rdquo;, k = 4</p> <p><strong>Output:</strong> &ldquo;1342&rdquo;</p> <p><strong>Explanation:</strong> The steps to obtain the minimum integer from 4321 with 4 adjacent swaps are shown.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> num = &ldquo;100&rdquo;, k = 1</p> <p><strong>Output:</strong> &ldquo;010&rdquo;</p> <p><strong>Explanation:</strong> It&rsquo;s ok for the output to have leading zeros, but the input is guaranteed not to have any leading zeros.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> num = &ldquo;36789&rdquo;, k = 1000</p> <p><strong>Output:</strong> &ldquo;36789&rdquo;</p> <p><strong>Explanation:</strong> We can keep the number without any swaps.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= num.length <= 3 * 10<sup>4</sup></code></li> <li><code>num</code> consists of only <strong>digits</strong> and does not contain <strong>leading zeros</strong>.</li> <li><code>1 <= k <= 10<sup>4</sup></code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minInteger

      public String minInteger(String num, int k)