Katkat

Implement Get and Insert in an Unrolled Linked List

IndeedSoftware Engineer · Technical Screen

Last updated

Implement indexed get and insert in an unrolled linked list, preserving block capacity, occupancy, sequence order, and split behavior.

Implement an unrolled linked list: an ordered sequence stored in linked blocks, where each block contains up to capacity integers. Support indexed get and indexed insert while preserving the sequence order.

Implement unrolled_list(operations: int[][], capacity: int) -> int[]. The list starts empty. Operations are:

  • [0, index, value]: insert value before the element currently at index; index == size appends. Return the new sequence size for this operation.
  • [1, index]: return the current element at index.

Return one integer per operation.

Constraints & Assumptions

  • 2 <= capacity <= 64; there are at most 20,000 operations.
  • Values are signed 32-bit integers. All indices are valid at the time of the operation: insertion uses 0 <= index <= size, and get uses 0 <= index < size.
  • Blocks are linked in sequence order. Every nonempty block has at most capacity values.
  • Except for the final block, maintain at least floor(capacity / 2) values per block. No deletion is required.
  • When inserting into a full block, split its values into two contiguous blocks and preserve their order. The exact split point may vary as long as capacity and occupancy requirements hold.
  • The operation encoding, capacity bound, occupancy convention, and returned insertion size are explicit practice choices for the reported get/insert task.
  • Implement the block-based representation rather than storing the entire sequence in one flat resizable array. Output depends only on sequence semantics, so structural invariants also require code review.

Examples

capacity = 3
operations = [[0,0,10],[0,1,30],[0,1,20],[1,1],[0,0,5],[1,3]]
result = [1,2,3,20,4,30]
capacity = 2
operations = [[0,0,7],[0,0,8],[0,1,9],[1,0],[1,1],[1,2]]
result = [1,2,3,8,9,7]

Hints

Hint 1

Locate a block and an offset: Subtract each block's element count while searching by index. At the insertion boundary, preserve which side of the existing element receives the new value, including append at the end.