Convert Array to DLL

Linked-List Fundamentals (Doubly LL) Easy

Given an array nums, convert it into a doubly linked list and return the head of the list.

Examples:

Input: nums = [1, 2, 3, 4]

Output: head -> 1 <-> 2 <-> 3 <-> 4

Input: nums = [7, 7]

Output: head -> 7 <-> 7

Input: nums = [3]

Constraints

  • n == nums.length
  • 0 <= n <= 100
  • 0 <= nums[i] <= 100

Hints

  • Create a Node structure containing val, next, and prev pointers. Initialize the head with the first element of nums[].
  • Iterate through nums[], creating new nodes, linking them bidirectionally (prev and next). Return the head of the doubly linked list.

Company Tags

Ernst & Young Zynga Epic Systems Qualcomm Medtronic HCL Technologies Flipkart Deloitte Oracle Intel Snowflake Teladoc Health Splunk Cloudflare GE Healthcare Broadcom Bungie Bloomberg Stripe Twilio Visa Morgan Stanley ARM eBay MongoDB TCS Cognizant Accenture Infosys Capgemini Wipro