Delete head of DLL

Linked-List Fundamentals (Doubly LL) Easy

Given the head of a doubly linked list, remove the node at the head of the linked list and return the head of the modified list.


The head is the first node of the linked list.

Examples:

Input: head -> 1 <-> 2 <-> 3

Output: head -> 2 <-> 3

Explanation: The node with value 1 was removed.

Input: head -> 7

Output: head

Explanation: Note that the head has null value after the removal.

Input: head -> 2 <-> 4

Constraints

  • n == Number of nodes in the linked list
  • 1 <= n <= 100
  • 0 <= ListNode.val <= 100

Hints

  • If the list is empty (head == None), return None. If there is only one node, remove it by returning None.
  • Update head to point to the next node (head.next). If the new head exists, set its prev = None to break the link. Return the updated head.

Company Tags

Ernst & Young Activision Blizzard American Express PayPal Red Hat McKinsey & Company Boston Consulting Group Swiggy Epic Games Shopify MongoDB Roblox Flipkart Splunk Oracle Zoho Ubisoft Visa DoorDash Reddit Medtronic Seagate Technology Wayfair Goldman Sachs Lyft TCS Cognizant Accenture Infosys Capgemini Wipro