Merge Nodes in Between Zeros | 2 Approaches | Leap Of Faith | Leetcode 2181 | codestorywithMIK

Описание к видео Merge Nodes in Between Zeros | 2 Approaches | Leap Of Faith | Leetcode 2181 | codestorywithMIK

Whatsapp Community Link : https://www.whatsapp.com/channel/0029...
This is the 25th Video of our Playlist "Linked List : Popular Interview Problems" by codestorywithMIK

In this video we will try to solve a good practice problem on Linked List : Merge Nodes in Between Zeros | 2 Approaches | Recursion Leap Of Faith | Leetcode 2181 | 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 : Merge Nodes in Between Zeros | 2 Approaches | Recursion Leap Of Faith | Leetcode 2181 | codestorywithMIK
Company Tags : Will update soon
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Intervie...
Leetcode Link : https://leetcode.com/problems/merge-n...


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 Approach
Time Complexity (T.C): O(n) Space Complexity (S.C): O(1)

Description:

This approach uses two pointers, P1 and P2, to traverse the linked list.
P1 is initialized to head.next and P2 is also set to P1.
It iterates through the list, summing values between nodes with value 0.
When a 0 is encountered, the sum is assigned to the node P1 is pointing to.
P1 and P2 pointers are then updated to continue processing the list.
This process is repeated until the end of the list is reached.
The method returns the modified list starting from head.next.
Approach 2: Recursive Approach
Time Complexity (T.C): O(n) Space Complexity (S.C): O(1)

Description:

This approach uses recursion to traverse and process the linked list.
The function first moves head to the next node (head = head.next).
If head is null, it returns head (base case).
A temporary pointer, temp, is used to traverse and sum values between nodes with value 0.
When a 0 is encountered, the sum is assigned to the current head node's value.
The function recursively calls itself to process the remainder of the list starting from temp.
This process continues until the entire list is processed.
The method returns the modified list starting from head.
Both approaches effectively merge nodes in a linked list by summing values between zeros and updating the list in place. The iterative approach uses a while loop and two pointers, while the recursive approach leverages function calls to traverse and update 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

Комментарии

Информация по комментариям в разработке