Menu Close

Return the maximum number you can get by changing at most one digit.

Given a positive integer num consisting only of digits 6 and 9.
Return the maximum number you can get by changing at most one digit
(6 becomes 9, and 9 becomes 6).

Input_1: 
Enter a number = 9669
Output: 9969
Explanation: 
Changing the first digit results in 6669.
Changing the second digit results in 9969.
Changing the third digit results in 9699.
Changing the fourth digit results in 9666. 
The maximum number is 9969.

Input_2:
Enter a number = 9996
Output: 9999
Explanation: Changing the last digit 6 to 9 results in the maximum number.
Example 3:

Input_3: num = 9999
Output: 9999
Explanation: No Need To Change
num=int(input('Enter a Number : '))

str1=list(str(num))
MAXI=0

for i in range(0,len(str1)):
	temp=str1.copy()

    temp[i] = '9' if temp[i]=='6' else '6'
	
    num1=int(''.join(temp))
	MAXI = num1 if num1>MAXI else MAXI

print(MAXI) if MAXI>num else print("No Need To Change")

Input_1:
Enter a Number : 9669
Output:
9969


Input_2:
Enter a Number : 9999
Output:
No Need To Change


Input_3:
Enter a Number : 6669
Output:
9669


Input_4:
Enter a Number : 9996
Output:
9999


Input_5:
Enter a Number : 6996
Output:
9996


Input_6:
Enter a Number : 6999
Output:
9999


Input_7:
Enter a Number : 6699
Output:
9699


Executed using terminal (python3) Linux

More Q