Implement RLE and Bit Packing Encoder
Implement an encoding algorithm that combines Run Length Encoding (RLE) and Bit Packing (BP). RLE encodes consecutive identical elements as RLE[element, frequency] and is applicable when there are 8 or more repetitions. BP packs exactly 8 non-RLE-eligible elements. RLE is always preferred: if the remaining elements at the end of a sequence are all identical (even if fewer than 8), they are encoded using RLE rather than BP. Examples: - [5,5,5] → RLE[5,3] - [1,1,1,2,3,4,5] → BP[1,1,1,2,3,4,5] - [0,0,0,0,0,0,0,0,0,2,3,4] → RLE[0,9], BP[2,3,4] - [1,1,1,1,1,1,1,1,1,2,2,1] → RLE[1,9], BP[2,2,1] - [0,0,0,0,0,0,0,0,0,2,2,2] → RLE[0,9], RLE[2,3]
Asked at:
Databricks
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
Late December, 2025
Databricks
Senior
Mid December, 2025
Databricks
Senior
There are two encoding types: RLE (Run Length Encoding) and BP (Bit Packing). RLE compresses consecutive repeated elements into the format RLE[element, frequency]. It requires a minimum of 8 repetitions to be applicable. Example: [1,1,1,1,1] → RLE[1,5] BP packs exactly 8 elements that are not eligible for RLE encoding. Default Rule: RLE is always preferred. This means if the remaining elements at the end of a sequence are all identical (even if fewer than 8), they are still encoded using RLE rather than BP. for e.g. [5,5,5] -> RLE[5,3] [1,1,1, 2, 3, 4, 5] -> BP[1,1,1,2,3,4,5] [0,0,0,0,0,0,0,0,0,2,3,4] -> RLE[0,9], BP[2,3,4] [1,1,1,1,1,1,1,1,1,2,2,1] -> RLE[1,9], BP[2,2,1] [0,0,0,0,0,0,0,0,0,2,2,2] -> RLE[0,9], RLE[2,3]
Hello Interview Premium
Your account is free and you can post anonymously if you choose.