num
to a string to easily access individual digits.max_num
and min_num
with the value of num
as a string.max_num
that is not 9
and replace all its occurrences with 9
to get the maximum value.min_num
and replace all its occurrences with 0
to get the minimum value.max_num
and min_num
back to integers.