Maximum 69 Number

EasyGreedygreedy

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

You are given a positive integer num whose decimal digits are all 6 or 9. You may change **at most one** digit, turning a 6 into a 9 or a 9 into a 6. Return the largest number you can obtain.

Examples

Input: num = 9669
Output: 9969
Changing the leftmost 6 gives 9969, the biggest of all options.
Input: num = 9996
Output: 9999
Only the last digit is a 6.
Input: num = 9999
Output: 9999
Any change would make the number smaller, so leave it.

Constraints

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

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More greedy problems