Tap here to switch tabs
Problem
Submissions

Problem: Rotated Digits

med
30 min
Try to solve the Rotated Digits problem.

Statement

An integer x is considered a good number if, after rotating each of its digits individually by 180180 degrees, the resulting number is a valid number that is different from x.

Each digit rotates according to the following rules:

  • 00, 11, and 88 rotate to themselves.

  • 22 and 55 rotate to each other.

  • 66 and 99 rotate to each other.

  • 33, 44, and 77 do not rotate to any valid digit and make the number invalid.

Given an integer n, return the count of good numbers in the range [1,n][1, n].

Constraints:

  • 1≤1 \leq n ≤104\leq 10^4

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Rotated Digits

med
30 min
Try to solve the Rotated Digits problem.

Statement

An integer x is considered a good number if, after rotating each of its digits individually by 180180 degrees, the resulting number is a valid number that is different from x.

Each digit rotates according to the following rules:

  • 00, 11, and 88 rotate to themselves.

  • 22 and 55 rotate to each other.

  • 66 and 99 rotate to each other.

  • 33, 44, and 77 do not rotate to any valid digit and make the number invalid.

Given an integer n, return the count of good numbers in the range [1,n][1, n].

Constraints:

  • 1≤1 \leq n ≤104\leq 10^4