Insert Greatest Common Divisors in Linked List | 2 Approaches | Leetcode 2807 | codestorywithMIK

Subscribers:
92,300
Published on ● Video Link: https://www.youtube.com/watch?v=BYXcK48Bzok



Duration: 0:00
3,376 views
184


Whatsapp Community Link : https://www.whatsapp.com/channel/0029...
This is the 28th Video of our Playlist "Array 1D/2D : Popular Interview Problems" by codestorywithMIK

In this video we will try to solve a simple LinkedList Problem : Insert Greatest Common Divisors in Linked List | 2 Ways | Iterative | Recursion | Leetcode 2807 | 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 : Insert Greatest Common Divisors in Linked List | 2 Ways | Iterative | Recursion | Leetcode 2807 | codestorywithMIK
Company Tags : will update soon
My solutions on Github(C++ & JAVA) - https://github.com/MAZHARMIK/Intervie...
Leetcode Link : https://leetcode.com/problems/insert-...


My DP Concepts Playlist :    • Roadmap for DP | How to Start DP ? | ...  
My Graph Concepts Playlist :    • Graph Concepts & Qns - 1 : Graph will...  
My Recursion Concepts Playlist :    • Introduction | Recursion Concepts And...  
My GitHub Repo for interview preparation : https://github.com/MAZHARMIK/Intervie...
Instagram :   / codestorywithmik  
Facebook :   / 100090524295846  
Twitter :   / cswithmik  
Subscribe to my channel :    / @codestorywithmik  

╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗
║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣
╠╗║╚╝║║╠╗║╚╣║║║║║═╣
╚═╩══╩═╩═╩═╩╝╚╩═╩═╝

Summary :
Approach-1 (Iterative)

Time Complexity (T.C): O(n)
Space Complexity (S.C): O(1)
In this iterative approach, we traverse the linked list using two pointers, currNode and nextNode. For each pair of consecutive nodes, we calculate the GCD of their values and insert a new node with this GCD value between them. The algorithm continues this process until the end of the list is reached. This approach operates in O(n) time, where n is the number of nodes in the list, and uses constant space O(1) since no extra memory is needed aside from the new nodes being inserted.

Approach-2 (Recursive)

Time Complexity (T.C): O(n)
Space Complexity (S.C): O(n) (due to recursive call stack)
In this recursive approach, we traverse the linked list recursively. The function processes the list from the end towards the beginning. For each pair of consecutive nodes, we calculate the GCD of their values, create a new node with this GCD value, and insert it between the current node and the next node. The recursion ensures that nodes are processed in reverse order. This approach also operates in O(n) time, but the space complexity is O(n) due to the system stack space required for recursive function calls.

Comparison:

Iterative Approach: Efficient in terms of space as it uses O(1) extra space, making it ideal for scenarios with memory constraints. However, the logic may be a bit harder to follow compared to recursion.
Recursive Approach: More elegant and easier to understand, but it incurs additional space overhead due to the recursive call stack, making it less optimal for very deep recursion.

✨ 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




Other Videos By codestorywithMIK


2024-09-20Lexicographical Numbers | Simple DFS | Leetcode 386 | codestorywithMIK
2024-09-20Shortest Palindrome | Multiple Ways | KMP Zindabaad | Leetcode 214 | codestorywithMIK
2024-09-18Different Ways to Add Parentheses | Simple Story To Code | Leetcode 241 | codestorywithMIK
2024-09-15Minimum Time Difference | Easy Approach | Detailed | Leetcode 539 | codestorywithMIK
2024-09-15DSA Shorts with MIK - 4
2024-09-15Find the Longest Substring Containing Vowels in Even Counts | Leetcode 1371 | codestorywithMIK
2024-09-14DSA Shorts with MIK - 3
2024-09-13Longest Subarray With Maximum Bitwise AND | Simple Observation | Leetcode 2419 | codestorywithMIK
2024-09-12XOR Queries of a Subarray | Simple Explanation | Leetcode 1310 | codestorywithMIK
2024-09-11Count the Number of Consistent Strings | Using Bit Manipulation | Leetcode 1684 | codestorywithMIK
2024-09-09Insert Greatest Common Divisors in Linked List | 2 Approaches | Leetcode 2807 | codestorywithMIK
2024-09-08Maximum Number of Moves to Kill All Pawns | Step By Step Detailed | Leetcode 3283 | codestorywithMIK
2024-09-08Leetcode Contest Qn-4 ka Khauf
2024-09-06Linked List in Binary Tree | Easy | Dry Run | Leetcode 1367 | codestorywithMIK
2024-09-05Delete Nodes From Linked List Present in Array | Simple | Dry Run | Leetcode 3217 | codestorywithMIK
2024-09-04Walking Robot Simulation | Detailed Simulation | Leetcode 874 | codestorywithMIK
2024-09-01Find the Student that Will Replace the Chalk | 2 Ways | Leetcode 1894 | codestorywithMIK
2024-09-01DSA Shorts with MIK - 2
2024-08-31Convert 1D Array Into 2D Array | 2 Approaches | Leetcode 2022 | codestorywithMIK
2024-08-30Palindrome Partitioning II | Using Blue Print | DP On Strings | Leetcode 132 | DP Concepts & Qns-28
2024-08-30Modify Graph Edge Weights | Using Dijkstra | Thought Process | Leetcode 2699 | codestorywithMIK