Skip to content

1323. Maximum 69 Number #2060

Answered by mah-shamim
mah-shamim asked this question in Q&A
Aug 16, 2025 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

We need to find the maximum number achievable by changing at most one digit in a given positive integer composed only of digits '6' and '9'. The key observation here is that changing a '6' to '9' increases the number's value, while changing a '9' to '6' decreases it. Therefore, the optimal strategy is to change the leftmost '6' to '9' to maximize the increase in the number's value. If there are no '6's, the number is already at its maximum value.

Approach

  1. Convert the number to a string: This allows easy traversal and manipulation of each digit.
  2. Traverse the digits from left to right: For each digit in the string:
    • If the digit is '6', change it to '9' and break out of the loop immediatel…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Aug 16, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Aug 16, 2025
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
2 participants