← Databricks Interview Insights
The decompression part is almost mechanical once you understand the format your encoder produces.
Clarify the encoding format and edge cases, then design a greedy left-to-right algorithm that at each position checks for runs of at least 8 identical values (RLE) or groups of exactly 8 distinct values (bit-packing). Implement the encoder to emit tagged segments and the decoder to reverse them, ensuring round-trip correctness and discussing trade-offs.
Pro tip: Explicitly define the output format (e.g., a byte stream with a tag byte per segment) and walk through a concrete example to demonstrate correctness and handle ambiguous cases like overlapping runs and packs.
Ask about input/output types, value range, and encoding format. Propose a simple tagged format (e.g., 0x01 for RLE, 0x02 for bit-pack) to make decoding unambiguous.
Scan left to right; at each position, first check if a run of at least 8 identical values exists. If so, emit an RLE segment; otherwise, collect up to 8 distinct values and emit a bit-packed segment if exactly 8 are available.
Read the tag byte, then decode the corresponding segment: for RLE, read the value and count; for bit-pack, read the packed bytes and unpack into 8 values. Append to output.
Consider runs longer than 8, fewer than 8 values at the end, and values that could be either RLE or bit-packed. Ensure round-trip correctness with tests.
Talk about time/space complexity, alternative encoding schemes, and potential improvements like using a single pass or handling larger runs more efficiently.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.