Code Room
CodingHardcod-g795
Subject Constraint searchLevel Senior–Staff~35 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

A confusing number is one that, when each digit is rotated 180 degrees, becomes a different valid number. Only digits 0,1,6,8,9 are rotatable (0->0, 1->1, 6->9, 8->8, 9->6); any number containing 2,3,4,5,7 is not rotatable at all. Rotating reverses the digit order. Given `n`, count how many integers in [1, n] are confusing numbers. 1 <= n <= 1000000000.

Implement
confusing_number_ii(n: int) → int
Examples
in[20]out6
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.