Maximum 69 Number

You are given a positive integer num made only of the digits 6 and 9. You may change at most one digit (a 6 becomes a 9, or a 9 becomes a 6). Return the largest number you can get.

30:00

Maximum 69 Number
easy
Free written solution
Topics
Companies

You are given a positive integer num made only of the digits 6 and 9. You may change at most one digit (a 6 becomes a 9, or a 9 becomes a 6). Return the largest number you can get.

Example 1:
Input: {"num":9669}
Output: 9969
Constraints:
  • 1≤num≤1041 \leq \text{num} \leq 10^4

  • num consists only of the digits 6 and 9.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"num":9669}

num = 9669. We may change at most one digit, and we want the result as large as possible.

digits of num

scan left to right →

9

x1000

6

x100

6

x10

9

x1

9: keep

6: candidate

flipped (6 turned upside down)

before

9669

→

now

9669

Variables
VariableValue
num9669
i-
DepthFunction Call
Stack empty
0/5