Maximum Score From Removing Substrings | 2 Approaches | With Proof | Leetcode 1717

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



Duration: 40:33
7,660 views
390


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

Using Approach-2 (i and j pointer approach), you can solve this problem as well - https://leetcode.com/problems/check-i...

In this video we will try to solve a very good Stack based problem : Maximum Score From Removing Substrings | 2 Approaches | With Proof | Leetcode 1717 | codestorywithMIK
We will also prove why the solution works.

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 : Maximum Score From Removing Substrings | 2 Approaches | With Proof | Leetcode 1717 | codestorywithMIK
Company Tags : META, AMAZON, GOOGLE
My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Intervie...
Leetcode Link : https://leetcode.com/problems/maximum...


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 :
Time Complexity: O(n)
Space Complexity: O(n)

In this approach, the solution leverages a stack to remove the specified substrings from the input string s. The algorithm proceeds in two main passes:

First Pass:
Identifies the substring (maxStr) that yields the higher score (max(x, y)) and removes it from s using the removeSubstring function.
The removeSubstring function uses a stack to track characters, removing pairs that match maxStr.
The score is updated by the number of removed pairs multiplied by the higher score value.
Second Pass:
The remaining string from the first pass is processed similarly to remove the substring (minStr) that yields the lower score (min(x, y)).
The score is again updated based on the number of removed pairs.
This method ensures that the higher score pairs are removed first, potentially increasing the overall score.

Approach 2: Without Stack
Time Complexity: O(n)
Space Complexity: O(1)

This approach optimizes space by removing the need for an auxiliary stack. Instead, it directly modifies the input string:

First Pass:
Similar to the first approach, it identifies and removes the maxStr substring from s.
Uses two pointers technique to keep track of valid characters in the string.
Updates the score based on the number of removed pairs multiplied by the higher score value.
Second Pass:
The modified string from the first pass is processed to remove the minStr substring.
Score is updated based on the number of removed pairs.
This approach achieves the same goal but with reduced space complexity, making it more efficient in terms of memory usage.


✨ Timelines✨
00:00 - Introduction
00:23 - Problem Explanation
02:11 - Approach-1 Thought Process (Using Stack)
08:49 - Proof of Approach-1
20:10 - Coding Approach-1
26:26 - Approach-2 Thought Process (Without Stack)
37:50 - Coding Approach-2



#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-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-12Range Sum Query - Mutable | Leetcode 307 | Segment Tree Concepts & Qns | Video 8 | codestorywithMIK
2024-07-12Number of Atoms | Made Easy | Full Dry Run | Leetcode 726 | Google | codestorywithMIK
2024-07-12Minimum Cost for Cutting Cake I & II | Thought Process | Leetcode 3218 | 3219 | codestorywithMIK
2024-07-12Robot Collisions | Made Easy | Dry Run | Leetcode 2751 | codestorywithMIK
2024-07-12Minimum Insertion Steps to Make a String Palindrome | Blue Print | DP On Strings | Leetcode 1312
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
2024-06-30Intersection of Two Arrays II | 2 Approaches | Easy Explanations | Leetcode 350 | codestorywithMIK