Submask range count

Write codeHard35 minGoogle style

Your task

A radio licence is issued as one bit pattern. The set may tune to a channel number only when every set bit of that number also appears in the licence, so the legal channels are exactly the patterns that fit inside mask. Given mask and an inclusive range from lo to hi, return how many legal channel numbers lie in that range. A licence can carry up to 30 bits and a range can cover most of a billion numbers, so neither listing the legal patterns nor walking the range will finish in time. All three values are non-negative and below 2^30, and a range where lo is greater than hi is empty and returns 0.

Examples

count_licensed_channels(mask: int, lo: int, hi: int) -> int
Example 1
Inputcount_licensed_channels(5, 0, 5)
Output4
Example 2
Inputcount_licensed_channels(5, 2, 4)
Output1
Example 3
Inputcount_licensed_channels(0, 0, 0)
Output1