Maximum 69 Number
Let’s work on this problem by taking the integer input, converting it into a string, and then processing each character.
We’ll follow these steps:
- Convert the integer number into a string, which makes it easier to manipulate individual digits.
- Loop over the characters in the string.
- When we encounter the first ‘6’, we change it to ‘9’ and break the loop. This is because the first ‘6’ from the left side contributes to the smallest value among all ‘6’s, changing it to ‘9’ will give us the maximum number.
- Convert the string back into an integer and return it.
Python solution:
|
|
This code will replace the first ‘6’ in the number with ‘9’, giving us the maximum possible number we can obtain with a single change.