Why condition if(digit>=5) is used here

if any other method to do this problem,please provide,this is bit confusing

Hey @aatish08 i dont think there is any simple method other than this to solve this question the logic behind this method is quite simple actually a number with smaller digits would be smaller than number with larger digits for example 464 bigger than 434 so thats why we replace digits greater than 5 with 5 - digit so that digit replacing it is smaller than initial digit, which makes the number smaller

Ok got this,Thank you

Ok got this,Thank you for the help

If your doubt is clear please mark it as resolved.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.