Minimum Possible Integer After at Most K Adjacent Swaps On Digits

You are given a string num representing the digits of a very large integer and an integer k. You are allowed to swap any two adjacent digits of the integer at most k times.

Return the minimum integer you can obtain also as a string.

Example 1
Inputnum = "4321", k = 4
Output"1342"
The steps to obtain the minimum integer from 4321 with 4 adjacent swaps produce 1342.
Example 2
Inputnum = "100", k = 1
Output"010"
It's ok for the output to have leading zeros, but the input is guaranteed not to have any leading zeros.

Constraints

  • 1 <= num.length <= 3 * 10^4
  • num consists of only digits and does not contain leading zeros.
  • 1 <= k <= 10^9

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate