Count Fancy Numbers
Updated
Problem statement
For the original problem description, pls checkout the image source at the very bottom of this web page 🐾🐾
Imagine you’re in a magical world where certain numbers are considered "fancy." A number is fancy if, when written in base-4, it only contains the digits 0 and 1—like secret codes known only to wizards. For example, 17 is fancy because its base-4 form, 101, uses only 0s and 1s, while 18 is not, as its base-4 form, 102, contains a forbidden 2. Now, your task is to discover how many of these special, fancy numbers exist below a given number, n. But beware! n can be as big as a billion, so you need a clever method—something faster than just checking every number individually.
Function
countFancyNumbers(n: int) → intExamples
Example 1
n = 1return = 0There are no positive integers less than 1.
Example 2
n = 10return = 3The fancy numbers less than 10 are {1, 4, 5}.
More Hudson River Trading interview questions
- Format a Signed Integer with CommasPHONE SCREEN · Seen Nov 2026
- Order and Batch Open-Close LifecyclePHONE SCREEN · Seen Nov 2026
- Count Palindrome Addition ChoicesOA · Seen Nov 2026
- Tilting Maze BallPHONE SCREEN · Seen Oct 2026
- Count Multiples of Three with Two SevensOA · Seen Oct 2026
- Recursively Expanded Shell Command CountsOA · Seen Oct 2026
- Rotate Matrix Regions Around the DiagonalsOA · Seen Oct 2026
- Maximum Diamond SumOA · Seen Oct 2026
- Smallest Most-Lit Street PositionOA · Seen Oct 2026
- Rearrange String by Alternating EndsOA · Seen Sep 2026
Similar questions at other companies
- Count Distinct Arrays After Decrement OperationsBloomberg LP · OABloomberg LP interview questions
- Frog Paths Without Long RunsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Get Triplet CountIBM · OAIBM interview questions
- Count Numbers with the Same Set-Bit CountMicrosoft · OAMicrosoft interview questions
- Count Reverse-Digit PairsVisa · OAVisa interview questions
- Get Triplet CountPoint72 · OAPoint72 interview questions
- Count Shipment SchedulesMorgan Stanley · OAMorgan Stanley interview questions
- Color a Grid with No Monochromatic Row or ColumnIntuit · OAIntuit interview questions
- Product of Subset MaximaArcesium · OAArcesium interview questions
- Find Maximum Number of Balanced CombinationsAmazon · OA