Question: Digits swap Time limit: 1 2 5 0 ms Memory limit: 2 5 6 MB You are given an integer N and another integer K

Digits swap
Time limit: 1250 ms
Memory limit: 256 MB
You are given an integer N and another integer K. You are allowed to perform at most K operations of the type:
Pick two arbitrary digits and swap them.
After each swap, the number must not contain any leading zeroes. Your task is to maximize the value of N after the swaps.
Standard Input
The first line contains two integers N and K.
Standard Output
Output one integer - the largest possible value of N after performing at most K swaps.
Constraints and Notes
1N1015
1K25
Swapping two digits should not result in a number with leading zeroes.
\table[[Input,Output],[,8865241]]
Explanation
We will perform the following sequence of swaps:
[1]85426[8] into 8854261.
88[5][4]261 into 8845261
88[4]52[6]1 into 8865241
The console should be able to give any input it wants
Digits swap Time limit: 1 2 5 0 ms Memory limit:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!