Submask range count
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.
count_licensed_channels(mask: int, lo: int, hi: int) → int[5,0,5]out4[5,2,4]out1[0,0,0]out1State 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.
[5,0,5]4not run yetsample[5,2,4]1not run yetsample[0,0,0]1not run yetsample