A deep-space probe compresses its status telemetry before transmission. Each status reading is encoded as either a single bit equal to 0, or a pair of bits that begins with 1 (so the pair reads as 10 or 11). A ground station receives one contiguous frame containing several encoded readings placed back to back, and the very last bit of the frame is always 0. Given such a frame, determine whether the last encoded reading in it occupies exactly one bit or exactly two bits.
Print true if the last encoded reading in the frame occupies exactly one bit, or false if it occupies two bits.
Example 1
Input
4 1 1 0 0
Expected
true
Explanation
The frame decodes greedily as "11", "0", "0": the first two bits form a two-bit reading, then each remaining bit is its own one-bit reading. The last reading (the final bit) is a single 0, so the answer is true.
Example 2
Input
6 1 1 1 0 1 0
Expected
false
Explanation
The frame decodes as "11", "10", "10": each 1 pulls in the bit right after it. The last reading spans the final two bits ("10"), so it is a two-bit reading and the answer is false.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →