How to delete all occurrences of a value in a doubly linked list

#100DaysOfCode – Day 91 Delete All Occurrences in a Doubly Linked List Given a doubly linked list and a key x, the task is to remove every node whose value equals x, and return the updated list. Example: Input: 2 <-> 2 <-> 10 <-> 8 <-> 4 <-> 2 <-> 5 <-> 2 Key: 2 Output: 10 <-> 8 <-> 4 <-> 5 My Approach Traversed the list using a pointer temp. For every node where temp.data == x: If it’s the head, shifted the head forward. Otherwise, re-linked the previous and next nodes to bypass the current one. Continued until the end of the list. Time Complexity: O(N) Space Complexity: O(1) Working with doubly linked lists reinforces how important pointer handling is. A single wrong link can break the entire structure but clean logic leads to elegant solutions! #100DaysOfCode #Java #DSA #LinkedList #GeeksforGeeks #ProblemSolving #CodingJourney #TakeUForward #CodeNewbie #LearningEveryday

  • graphical user interface

To view or add a comment, sign in

Explore content categories