Insert a Doubly Linked List Node at a Position
Updated
Problem statement
Given the values of a doubly linked list, a zero-based position, and a new value, insert a node before the current node at that position. Position values.length appends at the tail. Return the values in forward order.
For the practice runner, values serializes the list from head to tail. Build or reason about the doubly linked structure, connect both directions around the new node, update the head when needed, and return the serialized result.
Function
insertAtPosition(values: int[], position: int, value: int) → int[]Examples
Example 1
values = [1,3,4]position = 1value = 2return = [1,2,3,4]The new node is connected between 1 and 3.
Example 2
values = []position = 0value = 7return = [7]Inserting into an empty list creates its head and tail.
Constraints
0 <= values.length <= 10^5.-10^9 <= values[i], value <= 10^9.0 <= position <= values.length.
More Qualys Onsite Interview questions
- Delete a Doubly Linked List Node at a PositionONSITE INTERVIEW · Seen Oct 2026
- Find the Entry of a Linked List CycleONSITE INTERVIEW · Seen Oct 2026
- Implement Binary SearchONSITE INTERVIEW · Seen Oct 2026
- Rotate an Array Right by K StepsONSITE INTERVIEW · Seen Oct 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Reverse Linked ListByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
- Reverse Linked ListAutodesk · ONSITE INTERVIEWAutodesk interview questions
- Detect a Loop in a Linked ListEPAM · ONSITE INTERVIEWEPAM interview questions
- Insert After a Linked-List NodeAMD · ONSITE INTERVIEWAMD interview questions
- Reverse a Singly Linked ListGoogle · ONSITE INTERVIEWGoogle interview questions
- Process Singly Linked List OperationsSEDEMAC · ONSITE INTERVIEW
- Merge Two Sorted Linked ListsZS · ONSITE INTERVIEWZS interview questions
- Middle Node Of A Linked ListNVIDIA · ONSITE INTERVIEWNVIDIA interview questions
- Build and Check a Palindrome Linked ListOmnissa · ONSITE INTERVIEWOmnissa interview questions
- Reverse a Singly Linked ListGEP · ONSITE INTERVIEW