cswork / OA打开练习工作台

MicrosoftOA #43

Maximum Number Possible

估计中等评测数据准备中,可先阅读题面

考点(AI 标注)贪心调度字符串

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

Constraints

  • 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 :)

Example 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!

Example 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!

Example 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".

Example 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.