Each digit at most twice
InterviewTime limit3sMemory limit256 MB
Find the largest integer L not greater than U whose decimal digits each appear at most twice.
- Level
Medium5 of 10
- Topics
- Backtracking, Greedy, String
- Solved
- No attempts yet
Problem
Write a positive integer in decimal without leading zeros. The number satisfies the rule when no digit appears three or more times. For example satisfies the rule, and does not because the digit appears three times.
Given a positive integer , find the largest integer with that satisfies the rule. Every one-digit number satisfies the rule, so such an always exists.
Input
The first line contains an integer ().
Output
Print the largest integer not greater than whose decimal representation has no digit appearing three or more times.