Minimum Deletions to Make String Balanced | Multiple Approaches | Leetcode 1653 | codestorywithMIK
Whatsapp Community Link : https://www.whatsapp.com/channel/0029Va6kVSjICVfiVdsHgi1A This is the 22nd Video of our Playlist "Stack : Popular Interview Problems" by codestorywithMIK In this video we will try to solve a very good Stack based problem : Minimum Deletions to Make String Balanced | Multiple Approaches | Dry Run | Leetcode 1653 | 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 : Minimum Deletions to Make String Balanced | Multiple Approaches | Dry Run | Leetcode 1653 | codestorywithMIK Company Tags : will update soon My solutions on Github(C++ & JAVA) : https://github.com/MAZHARMIK/Interview_DS_Algo/blob/master/Stack/Minimum%20Deletions%20to%20Make%20String%20Balanced.cpp Leetcode Link : https://leetcode.com/problems/minimum-deletions-to-make-string-balanced 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 Instagram : https://www.instagram.com/codestorywithmik/ Facebook : https://www.facebook.com/people/codestorywithmik/100090524295846/ Twitter : https://twitter.com/CSwithMIK Subscribe to my channel : https://www.youtube.com/@codestorywithMIK ╔═╦╗╔╦╗╔═╦═╦╦╦╦╗╔═╗ ║╚╣║║║╚╣╚╣╔╣╔╣║╚╣═╣ ╠╗║╚╝║║╠╗║╚╣║║║║║═╣ ╚═╩══╩═╩═╩═╩╝╚╩═╩═╝ Summary : Approach 1: Using a Stack Time Complexity: O(n) Space Complexity: O(n) Description: This approach uses a stack to keep track of the characters. When encountering a 'ba' sequence, it pops the stack and increments the deletion count. This ensures the minimum deletions required to remove all 'ba' sequences in the string. Approach 2: Three Passes + O(2 * n) Space Time Complexity: O(3*n) Space Complexity: O(2*n) Description: This approach uses two auxiliary arrays, left_b and right_a, to count the number of 'b's to the left and 'a's to the right of each character in the string. By summing the values from these arrays for each position, it calculates the minimum deletions required to remove all 'ba' sequences. Approach 3: Two Passes + O(n) Space Time Complexity: O(2*n) Space Complexity: O(n) Description: This approach optimizes space by using a single auxiliary array right_a to count the number of 'a's to the right of each character. It then iterates through the string, keeping a running count of 'b's encountered so far, and computes the minimum deletions required by summing this count with the values in right_a. Approach 4: Constant Space Time Complexity: O(2*n) Space Complexity: O(1) Description: This approach further optimizes space usage by not using any auxiliary arrays. Instead, it counts the total number of 'a's in the string first, then iterates through the string while maintaining a running count of 'b's and decrementing the count of remaining 'a's as it encounters them. It computes the minimum deletions required using these counts. ✨ Timelines✨ 00:00 - Introduction 00:19 - Problem Explanation 03:06 - Approach 1 08:47 - Approach 2 19:05 - Code Approach 1 and 2 23:11 - Approach 3 26:26 - Code Approach 3 27:49 - Approach 4 32:53 - Code Approach 4 #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
Download
0 formatsNo download links available.