FastPrepInsert into an Unrolled Linked List
Problems/Insert into an Unrolled Linked List

Insert into an Unrolled Linked List

Indeed logoIndeed● MediumFULLTIMEPHONE SCREENONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: Two interview reports describe get and insert operations for fixed-capacity array nodes, including splitting a full node at the insertion position. This practice contract supplies boundary ownership and a finite matrix adapter.

An unrolled linked list is represented by nodes, where every row stores one node's active integer values and has length at most nodeCapacity. Concatenating the rows gives the logical list.

Insert value before logical position index, where index may equal the total size.

  • If the selected node has space, insert in that node.
  • If insertion occurs strictly inside a full node, keep the prefix and new value in that node and move the suffix into one newly inserted following node.
  • An index at a node boundary belongs to the following node when one exists.
  • Appending after a full final node creates a one-value node.

Return all node rows after insertion.

Function

insertUnrolled(nodes: int[][], nodeCapacity: int, index: int, value: int) → int[][]

Examples

Example 1

nodes = [[9,6,7,4,10]]nodeCapacity = 5index = 2value = 8return = [[9,6,8],[7,4,10]]

The full node splits at the insertion point: its prefix and 8 stay first, and the old suffix moves to the new node.

Example 2

nodes = [[1,2],[3]]nodeCapacity = 3index = 2value = 9return = [[1,2],[9,3]]

The boundary index belongs to the next node, which has capacity.

Constraints

  • 1 <= nodes.length <= 100000.
  • 1 <= nodes[i].length <= nodeCapacity <= 1000.
  • 0 <= index <= total number of stored values.
  • All values fit signed 32-bit integers.

More Indeed problems

  • Course Completion OrderPHONE SCREEN · Seen May 2025
  • Recipes You Can PreparePHONE SCREEN · Seen May 2025
  • Rotting Orange PropagationPHONE SCREEN · Seen May 2025
All Indeed interview questionsSee Indeed hiring insights
Saved
class Solution {
    public int[][] insertUnrolled(int[][] nodes, int nodeCapacity, int index, int value) {
        // Write your code here.
    }
}
Checking account…