Code RoomSector XOR folding
MediumPrep Room Coding #4857

Sector XOR folding

CodingAlgorithms & data structuresMid–Senior~22 min

A tape archive proves a restore by XOR folding the id of every sector it touched. starts and ends describe the runs in order: run i covers every sector id from starts[i] up to ends[i] inclusive, and a run whose start is greater than its end is a placeholder that covers nothing. Overlapping runs are normal, and a sector covered by two runs is folded in twice. Ids are below 2^30 and a single run can span hundreds of millions of sectors, so counting them one at a time is not an option. Return the XOR of every covered id, or 0 when the runs cover nothing at all. The two lists always have the same length.

Implement
archive_run_checksum(starts: list[int], ends: list[int]) → int
Examples
in[[1],[5]]out1
in[[0,10],[3,12]]out13
in[[7],[3]]out0
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 22 min
InputExpectedGot
[[1],[5]]1not run yetsample
[[0,10],[3,12]]13not run yetsample
[[7],[3]]0not run yetsample