DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
easy
LinkedList

Delete Node in a Linked List

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **Delete Node in a Linked List** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** Copy next value + skip next node **Edge Cases to Consider:** - (1) Node before tail - (2) Node is second-to-last - (3) Only guaranteed not to be last

Examples

Example 1
Input: [4,5,1,9], delete node 5
Output: [4,1,9]
Explanation: Basic delete
Example 2
Input: [4,5,1,9], delete node 1
Output: [4,5,9]
Explanation: Delete second-to-last
Example 3
Input: [1,2,3,4,5], delete node 1
Output: [2,3,4,5]
Explanation: Delete head (given node)

Constraints

  • ▪The number of nodes in the list is in the range [0, 500]
  • ▪-100 <= Node.val <= 100
  • ▪Solve in-place without copying node structures

Watch Out For Edge Cases

  • ▪Node before tail
  • ▪Node is second-to-last
  • ▪Only guaranteed not to be last
Frequently Asked At
AmazonMicrosoftAdobeTCS