Skip to content
DeepForgeby svx
All problems
EasyAlgorithmsal-275

Rotated Digits Count

Problem

Count how many numbers from 1 through n become a different valid number when each digit is rotated 180 degrees.

Digits 0, 1 and 8 stay valid and unchanged, 2, 5, 6 and 9 stay valid but change, and 3, 4 and 7 make the number invalid. A number counts only if it is valid and at least one digit changes.

Hint

A number containing any of 3, 4 or 7 can never be rotated at all.

Test cases

case 1
in: [10]
expected: 4
case 2
in: [1]
expected: 0
case 3
in: [2]
expected: 1
case 4
in: [20]
expected: 9
case 5
in: [100]
expected: 40
Starter codePython
def rotated_digits_count(n):
    # Your code here
    pass

5 test cases · run your code against them in the editor