Need help regarding CHDIGER

I am trying to solve Chef and a Beautiful Digit From March Long challenge. I have tried implementing it but am not able to get why I am getting the wrong answer. I have tried it for many input but I am getting correct for all the input. It would be great if someone could tell me what I am missing.
Attached the link to my code.

Hi!!Could you please describe what your logic is and what exactly your code is doing??. or add comments in between your code to show what each step is doing??.

One Test case i found where your solution fails is the following


423234 6

Your Answer - 223666

Correct Answer - 223466

Hope This Helps!!. :slight_smile:

Dude, The correct output would be 223366


The correct answer would 223466 only. You are only to append a digit and then remove a digit from any place. So you cannot shift the digits.

Thus to have 2nd digit as “2”, The first 3 needs to be removed. Also since 4<6 There is no need to remove 4. Thus the minimum number that can be obtained turns out to be 223466.

(223366 > 223346, and both 223366 and 223346 cannot be obtained by only appending and removing a digit.)

Got it. Thanks a lot for the help.

1 Like