FastPrepHybrid Run-Length and Bit-Packing Encoder
Problems/Hybrid Run-Length and Bit-Packing Encoder

Hybrid Run-Length and Bit-Packing Encoder

Databricks logoDatabricks● HardFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Databricks onsite interview. The report names the well-known hybrid run-length and bit-packing task for a stream of integers. It does not say whether the candidate had to encode, decode, or do both. We chose the usual encoding side. We also set the exact rule for choosing blocks, how the output is written, what happens when the stream ends, and the numeric limits. Our version is about 80% the same as the reported question.

Implement encodeHybridStream, which encodes the finite integer stream values using a fixed bitWidth.

Process values in arrival order and apply these rules:

  • Every maximal run of at least 8 equal values becomes one run-length block.
  • Values that do not belong to such a run form bit-packed segments. Split each segment from left to right into groups of 8; only the final group before a run-length block or the end of the stream may contain fewer values.
  • Represent each value in a bit-packed group using exactly bitWidth binary digits, most significant bit first, padding with leading zeroes. Concatenate the representations in input order.
  • Serialize a run-length block as RLE:<value>:<count>.
  • Serialize a bit-packed block as BP:<count>:<bits>, where count is the number of values in that block.

The stream becomes final immediately after the last array element. Return every completed block in emission order; no later value may revise a returned block.

Function

encodeHybridStream(values: int[], bitWidth: int) → String[]

Examples

Example 1

values = [3,3,3,3,3,3,3,3,1,2,3]bitWidth = 2return = ["RLE:3:8","BP:3:011011"]

The eight leading 3s form one run-length block. The remaining values use two bits each: 1 -> 01, 2 -> 10, and 3 -> 11.

Example 2

values = [1,2,1,2,1,2,1,2,3,3,3,3,3,3,3,3,0]bitWidth = 2return = ["BP:8:0110011001100110","RLE:3:8","BP:1:00"]

The alternating prefix fills one eight-value bit-packed block. The eight 3s form a run-length block, and the final 0 is flushed as a one-value bit-packed block at the end of the stream.

Example 3

values = [5,5,5,5,5,5,5]bitWidth = 3return = ["BP:7:101101101101101101101"]

A run of seven values is below the run-length threshold, so all seven values are encoded in the final bit-packed block.

Constraints

  • 1 <= values.length <= 100000.
  • 1 <= bitWidth <= 16.
  • 0 <= values[i] < 2^bitWidth.
  • The returned block strings must use the exact formats defined in the statement.

More Databricks Onsite Interview questions

  • Rolling Hit CounterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Path Between Two Nodes of a Fibonacci TreeONSITE INTERVIEW · Seen Oct 2026
  • Rectangular K-in-a-RowONSITE INTERVIEW · Seen Oct 2026
  • Customer Revenue with Direct ReferralsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • File Encryption Tree OptimizationPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Cipher Cover Interval EditingONSITE INTERVIEW · Seen Aug 2026
  • Concurrent Buffered File LoggerONSITE INTERVIEW · Seen Aug 2026
  • Key-Value Store with Hit CounterONSITE INTERVIEW · Seen Jul 2026
  • Blocking Keyed Cache with Waiting ReadersONSITE INTERVIEW · Seen Jul 2026
  • Snapshot Set IteratorPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026

Similar questions at other companies

  • Path Leaf Character IteratorGoogle · ONSITE INTERVIEWGoogle interview questions
  • Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
  • Deterministic Word Guess SolverAtlassian · ONSITE INTERVIEWAtlassian interview questions
  • Randomized Collection with Duplicate ValuesOkta · ONSITE INTERVIEWOkta interview questions
  • Cats, Rabbits, and Snails Board GameAsana · ONSITE INTERVIEW
  • Feature Flag Evaluation EngineCresta · ONSITE INTERVIEWCresta interview questions
  • IP Prefix StoreBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
  • File System Shell CommandsHarvey · ONSITE INTERVIEWHarvey interview questions

Databricks interview experiences

  • Databricks Senior SWE Onsite AI Rounds: 1 Experience
All Databricks interview questionsSee Databricks hiring insights
Saved
class Solution {
    public String[] encodeHybridStream(int[] values, int bitWidth) {
        // Write your code here.
    }
}
Checking account…