6
Idea is based on bubble sorting with limited steps k10
var minInteger = function (num, k) {11
if (num.length == 1) return num;13
let nums = num.split("");17
while (k && i < num.length - 1) {18
// step 0: if leading zero, check the next digit25
// step 1: find the min digit28
while (nums[p] !== "0" && j < nums.length && steps <= k) {29
if (nums[j] < nums[p]) p = j;34
// step 2: nums[i] is the current minimum digit --> check next digit41
// step 3: move the min digit to i43
[nums[p], nums[p - 1]] = [nums[p - 1], nums[p]];