Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

There acting S representing a positive number consisting of N digits. In one moveon choose some digit of S that is not equal to 5

There acting S representing a positive number consisting of N digits. In one moveon choose some digit of S that is not equal to 5 and replace it with the digit 5. What is the maximum number that can be obtained after making exactly K moves?
Write a function:
string solution(string &S, int K);
that, given a string S and an integer K, returns a string representing the maximum value that can be obtained after making exactly K moves. If making exactly K moves is impossible, return "IMPOSSIBLE".
Examples:
1. Given S=^{*}165232^{\circ} and K=3 the function should return "565552". This is the largest number that can be achieved by replacing three digits that are not already 5s with 5s.
2. Given S ="1839558" and K=4 the function should return "5855555".
3. Given S=^{*}5567855^{\circ} and K=4 the function should return "IMPOSSIBLE. It is not possible to make four moves because S contains only three digits that are not 5s.
Write an efficient algorithm for the following assumptions:
N is an integer within the range [1..100,000) onenes within the rannen 10000nt-

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

More Books

Students also viewed these Databases questions

Question

Address an envelope properly.

Answered: 1 week ago

Question

=+ What would it look like? Who should deliver it?

Answered: 1 week ago