Skip to content

Practice Rotated Digits

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#788
LeetCode Problem

Rotated Digits

Problem Statement

Count integers from 1 through n that change to a different valid number when every digit is rotated individually. Digits 0, 1 and 8 stay unchanged; 2 and 5 swap; 6 and 9 swap; 3, 4 and 7 are invalid. Keep the digit order. A number qualifies only if all digits are valid and at least one changes.

Source: Rotated Digits on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 10
Output
4

# Example 2

Input
n = 1
Output
0

# Example 3

Input
n = 2
Output
1

Constraints

1 <= n <= 10^4

Related LeetCode Problems

Practice more problems similar to Rotated Digits.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.