FastPrepFastPrep
Problem Brief

Maximum Number Possible

FULLTIMEOA

Given a String S representing positive digit containing n numbers, and given k ( number of moves), you can replace any number other then 5, return the maximun number possible within k moves

1Example 1

Input
s = "1839559", k = 4
Output
"5855555"
Explanation
This test case was added on 05-24-2025. You can find the relevant source ss in the Problem Source section below. Happy coding!

2Example 2

Input
s = "5567855", k = 4
Output
"IMPOSSIBLE"
Explanation
Becasue there are 3 digits in S that are not 5, so we cant do the 4th operation. This test case was added on 05-24-2025. You can find the relevant source ss in the Problem Source section below. Coding is fun!

3Example 3

Input
s = "165232", k = 3
Output
"555552"
Explanation
Becasue there are 3 digits in S that are not 5, so we cant do the 4th operation. This test case was added on 05-24-2025. You can find the relevant source ss in the Problem Source section below. Coding is fun! It comes from Source 2, but the expected output there seems to conflict with what’s shown in Source 1. Source 1 states the expected output is "565552".

4Example 4

Input
s = "165232", k = 3
Output
"565552"
Explanation
This test case comes from Source 1, but the expected output there seems to conflict with what’s shown in Source 2. Source 2 states the expected output is 555552.

Constraints

Limits and guarantees your solution can rely on.

  • An integer N in the range [1..100,000] — the length of a string S
  • An integer K in the range [0..100,000]
  • A string S of length N consisting only of digits (0-9), with no leading zeros.
  • Full constraints updated on 05-24-2025 :)
  • public String maximumNumberPossible(String s, int k) {
      // write your code here
    }
    
    Input

    s

    "1839559"

    k

    4

    Output

    "5855555"

    Sign in to submit your solution.