Code RoomUnpack sensor fields
EasyPrep Room Coding #4811

Unpack sensor fields

CodingNetworking & APIsAlgorithms & data structuresEntry–Mid~15 min

A sensor gateway squeezes every reading into one 32 bit word before putting it on the wire. field_widths describes the layout in order: field_widths[0] is the width of the first field, and that field occupies the lowest bits of the word, counting the least significant bit as bit 0. Each later field sits immediately above the one before it. Every field holds an unsigned value, and the widths add up to 31 or fewer, so any bits above the last field are padding and must be ignored. A width of 0 marks a field that was reserved but never wired up, and it reads as 0. packed_words holds one word per reading. Return one row per reading, in the order the words are given, each row holding that reading's field values in layout order. An empty layout gives every reading an empty row.

Implement
unpack_reading_fields(packed_words: list[int], field_widths: list[int]) → list[list[int]]
Examples
in[[2905,3983],[4,3,5]]out[[9,5,22],[15,0,31]]
in[[1074808776],[8,8]]out[[200,71]]
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
[[2905,3983],[4,3,5]][[9,5,22],[15,0,31]]not run yetsample
[[1074808776],[8,8]][[200,71]]not run yetsample