𝗗𝗮𝘆 𝟰𝟳/𝟭𝟬𝟬 | 𝗗𝗲𝗹𝗲𝘁𝗲 𝗡𝗼𝗱𝗲𝘀 𝗙𝗿𝗼𝗺 𝗟𝗶𝗻𝗸𝗲𝗱 𝗟𝗶𝘀𝘁 𝗣𝗿𝗲𝘀𝗲𝗻𝘁 𝗶𝗻 𝗔𝗿𝗿𝗮𝘆 Day 47 ✅ — Hash set meets linked list. 𝗧𝗼𝗱𝗮𝘆'𝘀 𝗣𝗿𝗼𝗯𝗹𝗲𝗺: ✅ 𝗣𝗿𝗼𝗯𝗹𝗲𝗺 #𝟯𝟮𝟭𝟳: Delete Nodes From Linked List Present in Array (Medium) 𝗪𝗵𝗮𝘁 𝗖𝗹𝗶𝗰𝗸𝗲𝗱: Remove all nodes whose values appear in a given array. Simple concept, but the implementation requires combining two data structures efficiently. The key? Convert array to 𝗛𝗮𝘀𝗵 𝗦𝗲𝘁 for O(1) lookups. Then traverse the linked list with dummy node pattern, checking each node against the set. Eighteen days of linked list practice means the traversal logic is automatic. My focus was purely on optimization—hash set instead of repeated array searching. 𝗠𝘆 𝗔𝗽𝗽𝗿𝗼𝗮𝗰𝗵: 👉 Convert nums array to HashSet 👉 Use dummy node for clean edge case handling 👉 Traverse list with prev and curr pointers 👉 If curr.val in set, skip node 👉 Otherwise, move forward Time: O(n + m), Space: O(m) where m = array size 𝗠𝘆 𝗥𝗲𝗮𝗹𝗶𝘇𝗮𝘁𝗶𝗼𝗻: Eighteen linked list problems. The dummy node pattern has appeared so many times it's muscle memory. When fundamentals are solid, you focus on what actually matters—choosing the right data structure. Hash sets turn O(n×m) solutions into O(n+m). That's the difference between passing and timing out. 𝗖𝗼𝗱𝗲:🔗 https://lnkd.in/gFMUU6bn 𝗗𝗮𝘆 𝟰𝟳/𝟭𝟬𝟬 ✅ | 𝟱𝟯 𝗺𝗼𝗿𝗲 𝘁𝗼 𝗴𝗼! #100DaysOfCode #LeetCode #LinkedList #HashSet #DataStructures #CodingInterview #SoftwareEngineer #Java #Algorithms #TimeComplexity #Programming #Optimization

To view or add a comment, sign in

Explore content categories