Unpack signed converter samples
A vibration logger packs signed converter samples end to end into 16 bit halfwords. Sample 0 starts at bit 0 of halfwords[0], counting the least significant bit of a halfword as bit 0. Each later sample starts where the one before it ended, and a sample that runs past bit 15 carries on in the low bits of the next halfword. Every sample is width bits wide and is held in two's complement, so a sample whose top bit is set reads as a negative value. width is between 2 and 12, and each halfword holds a value from 0 to 65535. Return the first count samples as signed values, in the order they were logged. Return an empty list when count is 0, and ignore any halfwords left over past the last sample asked for.
decode_sample_stream(halfwords: list[int], width: int, count: int) → list[int][[34801],4,4]out[1,-1,7,-8][[16259,24],5,5]out[3,-4,15,-16,1][[2047,128,0],12,3]out[2047,-2048,0]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.
[[34801],4,4][1,-1,7,-8]not run yetsample[[16259,24],5,5][3,-4,15,-16,1]not run yetsample[[2047,128,0],12,3][2047,-2048,0]not run yetsample