Remove Nth Node From End of List | 1 Pass | 2 Pass | Leetcode 19
Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A
This is the 19th Video of our Playlist "Leetcode Easy : Popular Interview Problems".
In this video we will try to solve a good practice problem : Remove Nth Node From End of List | Leetcode 19
Share your learnings on LinkedIn, Twitter (X), Instagram, Facebook(Meta) with #codestorywithmik & feel free to tag me.
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 : Remove Nth Node From End of List | 1 Pass | 2 Pass | Leetcode 19
Company Tags : ORACLE
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Linked%20List/Remove%20Nth%20Node%20From%20End%20of%20List.cpp
Leetcode Link : https://leetcode.com/problems/remove-nth-node-from-end-of-list/
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
Subscribe to my channel : https://www.youtube.com/@codestorywithMIK
Instagram : https://www.instagram.com/codestorywithmik/
Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/
Twitter : https://twitter.com/CSwithMIK
Approach Summary :
Approach-1 (2 Pass): This approach involves two passes through the linked list. In the first pass, the length of the linked list is calculated. Then, in the second pass, the node to be removed is identified and removed. If the node to be removed is the first node, a temporary pointer is used to update the head. The time complexity is O(n) for the two passes, and the space complexity is O(1) as it uses a constant amount of extra space.
Approach-2 (1 Pass): This approach uses a two-pointer technique to traverse the linked list in a single pass. Two pointers, fast and slow, are initially set to the head. The fast pointer is moved n nodes ahead. Then, both pointers are moved simultaneously until the fast pointer reaches the end. At this point, the slow pointer is at the node preceding the one to be removed. The removal is then performed by adjusting the pointers accordingly. This approach has a time complexity of O(n) for the single pass and a space complexity of O(1) as it uses only a constant amount of extra space.
╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝
✨ Timelines✨
00:00 - Introduction
01:03 - All think these corner cases
03:27 - 2 Pass Intuition
06:32 - Story Points
07:44 - Coding 2 Pass Solution
10:40 - 1 Pass Intuition
18:54 - Coding 1 Pass Solution
#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 #2024 #newyear