Maximum 69 Number

You are 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, where 6 becomes 9, and 9 becomes 6.

Example 1
Inputnum = 9669
Output9969
Changing the second digit results in 9969, which is the maximum possible number after at most one change.
Example 2
Inputnum = 9996
Output9999
Changing the last digit 6 to 9 results in the maximum number.

Constraints

  • 1 <= num <= 10^4
  • num consists of only 6 and 9 digits.

Asked at 7 companies

Practice questions like this out loud in a mock coding interview with a live AI interviewer. First one free.

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, what to keep, what's wrong, and the complexity of your solution.

Sign in to evaluate