Tap here to switch tabs
Problem
Submissions

Problem: Minimum Adjacent Swaps to Reach the Kth Smallest Number

Try to solve the Minimum Adjacent Swaps to Reach the Kth Smallest Number problem.

Statement

You are given a string num representing a large integer, and an integer k.

A wonderful integer is defined as a permutation of the digits in num that is strictly greater in value than num.

Return the minimum number of adjacent digit swaps needed to transform num into the kextthk^{ ext{th}} smallest wonderful integer.

Note: The test cases are generated such that the kextthk^{ ext{th}} smallest wonderful integer always exists.

Constraints:

  • 2≤2 \leq num.length ≤1000\leq 1000

  • 1≤1 \leq k ≤1000\leq 1000

  • num consists only of digits.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Adjacent Swaps to Reach the Kth Smallest Number

Try to solve the Minimum Adjacent Swaps to Reach the Kth Smallest Number problem.

Statement

You are given a string num representing a large integer, and an integer k.

A wonderful integer is defined as a permutation of the digits in num that is strictly greater in value than num.

Return the minimum number of adjacent digit swaps needed to transform num into the kextthk^{ ext{th}} smallest wonderful integer.

Note: The test cases are generated such that the kextthk^{ ext{th}} smallest wonderful integer always exists.

Constraints:

  • 2≤2 \leq num.length ≤1000\leq 1000

  • 1≤1 \leq k ≤1000\leq 1000

  • num consists only of digits.