InterviewBit Academy is now Scaler!
Learn Tech Skills from Scratch @ Scaler EDGE

Maximal String

Problem Description

Given a string A and integer B, what is maximal lexicographical stringthat can be made from A if you do atmost B swaps.

Problem Constraints

1 <= |A| <= 9

A contains only digits from 0 to 9.

1 <= B <= 5

Input Format

First argument is string A.

Second argument is integer B.

Output Format

Return a string, the naswer to the problem.

Example Input

Input 1:

A = "254"
B = 1

Input 2:

A = "254'
B = 2

Example Output

Output 1:


Output 2:


Example Explanation

Explanation 1:

 Swap 2 and 5.

Explanation 2:

Swap 2 and 5 then swap 4 and 2.

NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Maximal String on Interview Code Editor
  • Hint 1
  • Solution Approach
  • Complete Solution
Asked In:


Click here to start solving coding interview questions