Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Parse Framed Sensor Data Packets

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Parse Framed Sensor Data Packets. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given a list of byte values stream representing data received over a serial interface, parse all valid sensor packets and return their decoded fields. Each packet has the format [0xAA, length, sensor_id, payload..., checksum], where length is the number of bytes in [sensor_id, payload...], and checksum equals (length + sensor_id + sum(payload)) % 256. Ignore noise bytes before a header, skip malformed packets, and continue scanning for the next valid packet.

Constraints

  • 1 <= len(stream) <= 10^5
  • 0 <= stream[i] <= 255
  • 1 <= length <= 255 for a valid packet
  • A valid packet must contain exactly length + 3 bytes including header, length, and checksum

Function Signature

def parse_sensor_packets(stream):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output