Building logic for the problem

I have understood the question but I’m unable to build an approach for this problem

hello @vketan182

approach is simple
read a number as string (say s) .
if left most character is ā€˜9’

  • then leave the leftmost character as it is and for other characters simpl replace s[i] with min(s[i],ā€˜9’-s[i])

else:

  • for each i replace s[i] with min(s[i],ā€˜9’-s[i])

print s