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
Examples
01 · Example 1
s = "1839559" k = 4 return = "5855555"
This test case was added on 05-24-2025. You can find the relevant source ss in the Problem Source section below. Happy coding!
02 · Example 2
s = "5567855" k = 4 return = "IMPOSSIBLE"
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!
03 · Example 3
s = "165232" k = 3 return = "555552"
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".
04 · Example 4
s = "165232" k = 3 return = "565552"
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
An integer N in the range [1..100,000] — the length of a string SAn 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 :)More Microsoft problems
- Rank Open BusinessesPHONE SCREEN · Seen May 2026
- Retain Top K ValuesPHONE SCREEN · Seen May 2026
- In-Memory SQL with CSV InitializationONSITE INTERVIEW · Seen May 2026
- Order Records by Matching Start and EndONSITE INTERVIEW · Seen May 2026
- Recover Corrupted Master PageONSITE INTERVIEW · Seen Feb 2026
- Distinct Number Line MovesOA · Seen Oct 2025
- Minimum Round Trip LengthsOA · Seen Aug 2025
- Programmer StringsOA · Seen Aug 2025
public String maximumNumberPossible(String s, int k) {
// write your code here
}
s"1839559"
k4
expected"5855555"
checking account