FastPrepPack Stream Chunks into Fixed-Capacity Nodes
Problems/Pack Stream Chunks into Fixed-Capacity Nodes

Pack Stream Chunks into Fixed-Capacity Nodes

Broadcom Limited logoBroadcom Limited● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The source defines greedy packing of nodes into 32-byte pieces, with an example of 50 bytes plus 20 bytes. Here the linked list comes as ordered byte arrays. Our version is about 95% the same as the reported question.

A byte stream is delivered as a finite ordered sequence of chunks. You are given those chunks as chunks, where each integer is one byte value.

Pack the bytes, without reordering or dropping any value, into consecutive nodes of capacity 32. Fill every node greedily to length 32 before starting the next node. Only the final node may contain fewer than 32 bytes.

Return the linked-list payloads in order as a two-dimensional array, one row per node. If the stream ends before returning any bytes, return an empty array.

Function

packStreamChunks(chunks: int[][]) → int[][]

Examples

Example 1

chunks = [[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49],[50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69]]return = [[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31],[32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63],[64,65,66,67,68,69]]

The two calls provide 70 bytes. Greedy capacity-32 packing produces node lengths [32,32,6].

Example 2

chunks = [[1,2],[3]]return = [[1,2,3]]

All three bytes fit in the final partial node and preserve stream order.

Constraints

  • 0 <= chunks.length <= 4.
  • 1 <= chunks[i].length.
  • The total number of bytes is at most 3000.
  • 0 <= chunks[i][j] <= 255.

Similar questions at other companies

  • Deep Copy a Random-Pointer ListAmazon · ONSITE INTERVIEW
  • Merge One List Between Two PositionsOracle · ONSITE INTERVIEWOracle interview questions
  • Insert into an Unrolled Linked ListIndeed · PHONE SCREEN · ONSITE INTERVIEWIndeed interview questions
  • Insert into a Sorted Circular ListMeta · ONSITE INTERVIEWMeta interview questions
  • Deep Copy a Random-Pointer ListBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
  • Minimize Task Resource ConsumptionNVIDIA · OANVIDIA interview questions
  • Largest Microorganism After ConsumptionOpenAI · OAOpenAI interview questions
  • Buffet Day GainsUpstart · OAUpstart interview questions
  • Deep Copy a Random-Pointer ListSuperhuman · PHONE SCREENSuperhuman interview questions
  • Sustained Overspeed AlertsFleetx · ONSITE INTERVIEW
See Broadcom Limited hiring insights
Saved
class Solution {
    public int[][] packStreamChunks(int[][] chunks) {
        // Return one byte-array row per packed node.
    }
}
Checking account…