Delete Nodes from Linked List Present in Array on LeetCode

🚀 Day 83 of #100DaysOfCode Solved 3217. Delete Nodes from Linked List Present in Array on LeetCode 🔗 🧠 Key Insight: We need to remove all nodes from the linked list whose values exist in a given array 👉 Fast lookup is required → use a HashSet ⚙️ Approach (HashSet + Traversal): 1️⃣ Store all array elements in a HashSet 🔹 set.add(nums[i]) 2️⃣ Use a dummy node before head 🔹 Helps handle deletion at head easily 3️⃣ Traverse the list: 🔹 If node.next.val exists in set → delete it 👉 node.next = node.next.next 🔹 Else → move forward 4️⃣ Return dummy.next ⏱️ Time Complexity: O(n + m) 📦 Space Complexity: O(m) #100DaysOfCode #LeetCode #DSA #LinkedList #HashSet #TwoPointers #Java #InterviewPrep #CodingJourney

  • No alternative text description for this image

To view or add a comment, sign in

Explore content categories