Tap here to switch tabs
Problem
Submissions

Problem: Confusing Number II

med
30 min
Try to solve the Confusing Number II problem.

Statement

A confusing number is a positive integer that, when rotated by 180180 degrees, yields a valid number that is different from the original number.

The rotation rules for individual digits are as follows:

  • 00, 11, and 88 rotate to 00, 11, and 88 respectively.

  • 66 and 99 rotate to 99 and 66 respectively.

  • All other digits (22, 33, 44, 55, and 77) become invalid when rotated.

When a number is rotated by 180180 degrees, each of its digits is rotated and the order of the digits is reversed. Any leading zeros in the resulting rotated number are omitted.

Given an integer n, return the total count of confusing numbers in the inclusive range from 11 to n.

Constraints:

  • 1≤1 \leq n ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Confusing Number II

med
30 min
Try to solve the Confusing Number II problem.

Statement

A confusing number is a positive integer that, when rotated by 180180 degrees, yields a valid number that is different from the original number.

The rotation rules for individual digits are as follows:

  • 00, 11, and 88 rotate to 00, 11, and 88 respectively.

  • 66 and 99 rotate to 99 and 66 respectively.

  • All other digits (22, 33, 44, 55, and 77) become invalid when rotated.

When a number is rotated by 180180 degrees, each of its digits is rotated and the order of the digits is reversed. Any leading zeros in the resulting rotated number are omitted.

Given an integer n, return the total count of confusing numbers in the inclusive range from 11 to n.

Constraints:

  • 1≤1 \leq n ≤109\leq 10^9