Back to Browse

Delete Nodes From Linked List Present in Array | Simple | Dry Run | Leetcode 3217 | codestorywithMIK

9.7K views
Sep 6, 2024
15:18

Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A This is the 27th Video of our Playlist "Array 1D/2D : Popular Interview Problems" by codestorywithMIK In this video we will try to solve a simple LinkedList Problem : Delete Nodes From Linked List Present in Array | Clean | Simple | Dry Runs | Leetcode 3217 | codestorywithMIK I will explain the intuition so easily that you will never forget and start seeing this as cakewalk EASYYY. We will do live coding after explanation and see if we are able to pass all the test cases. Also, please note that my Github solution link below contains both C++ as well as JAVA code. Problem Name : Delete Nodes From Linked List Present in Array | Clean | Simple | Dry Runs | Leetcode 3217 | codestorywithMIK Company Tags : Amazon My solutions on Github(C++ & JAVA) - https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Linked%20List/Delete%20Nodes%20From%20Linked%20List%20Present%20in%20Array.cpp Leetcode Link : https://leetcode.com/problems/delete-nodes-from-linked-list-present-in-array My DP Concepts Playlist : https://youtu.be/7eLMOE1jnls My Graph Concepts Playlist : https://youtu.be/5JGiZnr6B5w My Recursion Concepts Playlist : https://www.youtube.com/watch?v=pfb1Zduesi8&list=PLpIkg8OmuX-IBcXsfITH5ql0Lqci1MYPM My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Interview_DS_Algo Instagram : https://www.instagram.com/codestorywithmik/ Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/ Twitter : https://twitter.com/CSwithMIK Subscribe to my channel : https://www.youtube.com/@codestorywithMIK ╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗ ║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣ ╠╗║╚╝║║╠╗║╚╣║║║║║═╣ ╚═╩══╩═╩═╩═╩╝╚╩═╩═╝ Summary : The goal of the solution is to remove nodes from a linked list if their values are present in a given array nums. The approach leverages a HashSet for efficient O(1) lookups. HashSet Construction: Convert the array nums into a HashSet to enable constant-time checks for whether a node's value is in the array. Skipping Initial Nodes: Start by moving the head pointer forward if the initial nodes' values are in the HashSet. This ensures that the head of the list points to the first node that is not in nums. Traversing the List: Use two pointers, prev and curr, to traverse the remaining list: If curr.val is not in the HashSet, move both prev and curr forward. If curr.val is in the HashSet, remove the node by adjusting prev.next to skip the curr node. Edge Case Handling: This approach handles cases where the entire list is removed (resulting in a null list) or where no nodes are removed. By iterating through the list just once, the algorithm ensures an efficient solution with a time complexity of O(n), where n is the number of nodes in the list. ✨ Timelines✨ 00:00 - Introduction #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge#leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview#interviewtips #interviewpreparation #interview_ds_algo #hinglish #github #design #data #google #video #instagram #facebook #leetcode #computerscience #leetcodesolutions #leetcodequestionandanswers #code #learning #dsalgo #dsa #newyear2024

Download

0 formats

No download links available.

Delete Nodes From Linked List Present in Array | Simple | Dry Run | Leetcode 3217 | codestorywithMIK | NatokHD