Build a Doubly Linked List from an Array of Values

Implement buildDLL

Given an array of values, build a doubly linked list holding them in the same order — every node needs a correctly wired .next pointing forward and .prev pointing backward, not just the forward chain a singly linked list would need. The forward links alone are no different from building any singly linked list. What makes this a doubly linked list is the second pointer: as each new node joins the chain, its .prev needs to be set to whatever the current tail is, so the list can be walked backward from any node just as easily as forward — the whole reason a doubly linked list exists in the first place.

Example 1:

Input: values = [6,2,9]

Output: [6,2,9]

Example 2:

Input: values = [4]

Output: [4]

Example 3:

Input: values = []

Output: []

+ 4 hidden test cases run on Submit.

Constraints:

  • 0 ≤ number of values ≤ 200
  • -1000 ≤ each value ≤ 1000
  • This platform's judge reads back only the forward (next) traversal — the point of the exercise is correctly wiring both links while building, not what the wire format can verify

values =

[6, 2, 9]