Code RoomSubmask range count
HardPrep Room Coding #4860

Submask range count

CodingAlgorithms & data structuresSenior–Staff~35 min

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.

Implement
count_licensed_channels(mask: int, lo: int, hi: int) → int
Examples
in[5,0,5]out4
in[5,2,4]out1
in[0,0,0]out1
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.

0:00 of about 35 min
InputExpectedGot
[5,0,5]4not run yetsample
[5,2,4]1not run yetsample
[0,0,0]1not run yetsample