Google | Phone Screen | Find Confusing Numbers

Given an array of N numbers from 1 to N. A number is confusing if it becomes another number in the array after we rotate "the whole number" by 180 degrees. Find the total number of the confusing numbers in this array. For example, N = 13, and the array is [1, 2, 3 ... , 11, 12, 13]. The confusing numbers are [6, 9, 10]. Hence return 3.

Some examples:
161 -> 191
9016 -> 9106

PS: Only 0, 1, 6, 8, 9 are still valid numbers after rotation by 180 degrees. Other digits are not valid after the rotation.

Follow up: How do you find the total number of confusing numbers in the array efficiently if N is big?

https://leetcode.com/problems/confusing-number/
https://leetcode.com/problems/confusing-number-ii/ (premium)

Comments (6)