Internet checksum
Compute the 16-bit Internet checksum (RFC 1071) over a list of byte values. Treat the data as a sequence of 16-bit big-endian words; if the byte count is odd, pad with a single trailing zero byte. Sum the words in ones-complement arithmetic (fold any carry out of bit 15 back into the low bits), then return the bitwise complement of the final sum, masked to 16 bits. An empty input yields 0xFFFF.
Implement
internet_checksum(data: list[int]) → intExamples
in
[[0,1,242,3]]out3579What 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 25 min
solution.py
InputExpectedGot
[[0,1,242,3]]3579not run yetsample