Number of Atoms | Made Easy | Full Dry Run | Leetcode 726 | Google | codestorywithMIK

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



Duration: 0:00
9,578 views
506


iPad PDF Notes - https://github.com/MAZHARMIK/Intervie...
Whatsapp Community Link : https://www.whatsapp.com/channel/0029...
This is the 21st Video of our Playlist "Stack : Popular Interview Problems" by codestorywithMIK

In this video we will try to solve a very good Stack based problem : Number of Atoms | Made Easy | Full Dry Run | Leetcode 726 | Google | 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 : Number of Atoms | Made Easy | Full Dry Run | Leetcode 726 | Google | codestorywithMIK
Company Tags : GOOGLE, APPLE
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Intervie...
Leetcode Link : https://leetcode.com/problems/number-...


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 :
Use a Stack to Handle Nested Structures:

A stack is used to manage the nested nature of chemical formulas. Each level of parentheses in the formula corresponds to a new map on the stack that tracks element counts within that scope.
Iterate Through the Formula:

As we iterate through the formula string, we encounter different characters:
'(': Push a new empty map onto the stack to start a new scope.
')': Pop the top map from the stack (representing the current scope), parse the subsequent number (if any) as the multiplier, and merge this scope's counts into the next map on the stack, adjusting counts by the multiplier.
Element Symbols and Counts: Parse element symbols (which can be a single uppercase letter followed by zero or more lowercase letters) and their counts (if any). Update the count of each element in the current top map of the stack.
Merge Maps and Adjust Counts:

When encountering a closing parenthesis, the map from the current scope is merged into the next map on the stack, with counts adjusted by any multiplier following the closing parenthesis.
Construct the Result:

After parsing the entire formula, the stack will contain one map representing the final count of each element. This map is sorted lexicographically (by element name) to construct the result string in the required format: each element followed by its count (if greater than one).
Return the Result:

The result string is built by iterating over the sorted map and concatenating each element and its count to the result string.
This method efficiently handles nested structures and ensures that all elements and their counts are accurately represented in the final result.


✨ Timelines✨
00:00 - Introduction
00:23 - Problem Explanation
04:59 - Why Stack ?
12:00 - Simplest Thought Process + Complete Dry Run
23:35 - Coding it up

#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-07-22Sort the Jumbled Numbers | 2 Approaches | Leetcode 2191 | codestorywithMIK
2024-07-20Minimum Operations to Make Array Equal to Target | Minimum Number of Increments|Leetcode 3229 & 1526
2024-07-19Build a Matrix With Conditions | BFS | DFS | Detailed Explanation | Leetcode 2392 | codestorywithMIK
2024-07-19Palindrome Partitioning | Using Blue Print | DP On Strings | Leetcode 131 | DP Concepts & Qns-27
2024-07-18Find Valid Matrix Given Row and Column Sums | Simple Approach | Leetcode 1605 | codestorywithMIK
2024-07-18Number of Good Leaf Nodes Pairs | Simple DFS | Dry Run | Leetcode 1530 | codestorywithMIK
2024-07-17Lucky Numbers in a Matrix | 2 Approaches | Dry Run | Leetcode 1380 | codestorywithMIK
2024-07-16Number of Good Leaf Nodes Pairs | Using Graph And BFS | Dry Run | Leetcode 1530 | codestorywithMIK
2024-07-14Step-By-Step Directions From a Binary Tree Node to Another | 2 Approaches | Leetcode 2096
2024-07-13Create Binary Tree From Descriptions | Simplest Approach | Leetcode 2196 | codestorywithMIK
2024-07-12Number of Atoms | Made Easy | Full Dry Run | Leetcode 726 | Google | codestorywithMIK
2024-07-11Maximum Score From Removing Substrings | 2 Approaches | With Proof | Leetcode 1717
2024-07-09Reverse Substrings Between Each Pair of Parentheses | 2 Approaches | Leetcode 1190 |codestorywithMIK
2024-07-08Crawler Log Folder | 2 Approaches | Dry Runs | Leetcode 1598 | codestorywithMIK
2024-07-07Average Waiting Time | Simple Simulation | Leetcode 1701 | codestorywithMIK
2024-07-06Range Update Query | Lazy Propagation | Segment Tree Concepts & Qns | Video 7 | codestorywithMIK
2024-07-06Find the Winner of the Circular Game | 3 Approaches | Leetcode 1823 | codestorywithMIK
2024-07-05Pass the Pillow | 2 Approaches | Easy Explanations | Leetcode 2582 | codestorywithMIK
2024-07-05Water Bottles | 3 Approaches | Easy Explanations | Leetcode 1518 | codestorywithMIK
2024-07-02Minimum Difference Between Largest and Smallest Value in Three Moves | 2 Approaches | Leetcode 1509
2024-07-02Merge Nodes in Between Zeros | 2 Approaches | Leap Of Faith | Leetcode 2181 | codestorywithMIK