Code RoomMeeting room free hours
EasyPrep Room Coding #4851

Meeting room free hours

CodingAlgorithms & data structuresEntry–Mid~15 min

A meeting room packs one day of its calendar into a single integer. Bit h of that word, counting the least significant bit as bit 0, is set when hour h is already booked, and the hours of a day run from 0 to 23. Bits 24 and above carry unrelated housekeeping and must be ignored, even when they are set. busy_masks holds one word per day. Return one entry per day, in the order the days are given, holding the earliest hour at which a free block of hours_needed consecutive hours starts. The whole block has to sit inside the day, so it ends at hour 23 or earlier. Return -1 for a day with no such block, which covers every day when hours_needed is more than 24. hours_needed is never negative, and 0 means nothing to book, so every day answers 0.

Implement
earliest_free_hour(busy_masks: list[int], hours_needed: int) → list[int]
Examples
in[[511,0],3]out[9,0]
in[[16777215],1]out[-1]
in[[12,0,4095],5]out[4,0,12]
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 15 min
InputExpectedGot
[[511,0],3][9,0]not run yetsample
[[16777215],1][-1]not run yetsample
[[12,0,4095],5][4,0,12]not run yetsample