At Nordic Embedded, a microcontroller receives a stream of sensor flags where each reading is either 0 or 1. Because RAM is limited, write code that packs every 8 flags into one byte and returns the packed result using only constant extra working memory beyond the output array.
Implement a function pack_sensor_flags(flags).
flags of integers, where each value is either 0 or 1[0, 255]0.Example 1
flags = [1,0,1,0,0,0,0,1][161]10100001, which equals 161.Example 2
flags = [1,1,1,1,1,1,1,1, 0,0,0,0][255, 0]11111111 = 255. The remaining 4 flags become 00000000 after padding.0 <= len(flags) <= 10^5flags[i] is either 0 or 1O(1) extra working memory, excluding the returned output list