FastPrepInsert into the Middle of a Linked List
Problems/Insert into the Middle of a Linked List

Insert into the Middle of a Linked List

AMD logoAMD● EasyINTERNONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks to insert in the middle of a linked list without an even-length policy. This exercise authors the ceil(n/2)position, empty behavior, bounds and interface; approximate source match80%. An exact source date is not available.

Insert one new node with value after the first ceil(n/2) original nodes, where n is the list length. For even n, this is between the two halves; for odd n, insert immediately after the central node. For n=0, create the head. Preserve the original node order and return the updated head.

Function

insertAtMiddle(head: ListNode, value: int) → ListNode

Examples

Example 1

head = [1,2,3,4]value = 9return = [1,2,9,3,4]

For length4, the new node follows the first2original nodes.

Example 2

head = [1,2,3]value = 9return = [1,2,9,3]

For length3, the central node is2 and the new node follows it.

Constraints

  • 0 <= head.length <= 500.
  • -1000000 <= head[i] <= 1000000.
  • -1000000 <= value <= 1000000.
  • The input list is acyclic.

More AMD problems

  • Insert After a Linked-List NodeONSITE INTERVIEW · Seen Oct 2026
  • LRU CacheONSITE INTERVIEW · Seen Oct 2026
  • Lowest Common Ancestor of a Binary TreePHONE SCREEN · Seen Oct 2026
All AMD interview questionsSee AMD hiring insights
Saved
public ListNode insertAtMiddle(ListNode head, int value) {
    // Write your code here.
}
Checking account…