Problem · Dynamic Programming
Count Good Numbers
Learn this problemProblem statement
A positive integer is good when it satisfies all of the following conditions:
- It does not contain the digit
0. - Each digit appears at most once.
- No interior digit is smaller than both of its adjacent digits.
Given a positive integer m, return the number of good integers in the inclusive range [1, m].
Function
countGoodNumbers(m: int) → intExamples
Example 1
m = 21return = 18The good numbers are 1 through 9, 12 through 19, and 21. The numbers 10 and 20 contain 0, while 11 repeats a digit. Two-digit numbers have no interior digit.
More Google problems
- Deduplicate Logs: Keep FirstONSITE INTERVIEW · Seen Jul 2026
- Deduplicate Logs: Keep LatestONSITE INTERVIEW · Seen Jul 2026
- Find a Template Across Binary-Tree LeavesONSITE INTERVIEW · Seen Jul 2026
- Maximum Programmer-Problem MatchingONSITE INTERVIEW · Seen Jul 2026
- Minimum Direction ViolationsONSITE INTERVIEW · Seen Jul 2026
- Stream Latest Log VersionsONSITE INTERVIEW · Seen Jul 2026
- Stream Unique Logs in Timestamp OrderONSITE INTERVIEW · Seen Jul 2026
- Top-K IP Addresses from File RecordsONSITE INTERVIEW · Seen Jul 2026