1717. Maximum Score From Removing Substrings | Why not DP | Greedy | Stack | 2 Pointer | 2 Approach

  Рет қаралды 6,160

Aryan Mittal

Aryan Mittal

Күн бұрын

Пікірлер: 29
@ARYANMITTAL
@ARYANMITTAL 3 ай бұрын
So, everyone asks to not put spoiler in titles, I put this on the basis of my experience with other leetcode tutorials of my time (eg: 3 years back, when i was preparing for internship, whenever i search for any leetcode problem, there used to come 1 channel's video most often, i'll not name it, though it was good, but as soon as there used to hard follow up of any problem or hard variant, he used to skip it & i hated that part everytime, that atleast write in beginning or tell you will teach very basic stuff) . Thus, i write in title or tell in beginning that what all you will get from video & look for that part accordingly. (Why DP, was very specific to me! I just thought, somehow DP was intuitive to me but later realised that it can't solve, so yeah discussed that too 🌚)
@rev_krakken70
@rev_krakken70 3 ай бұрын
I am happy today, since i think this is the first time i came up with an algorithm on my own and the fact that i did not consider any existing template and stuff before coding the solution, and I was able to beat 100% with my solution
@kgjr.6224
@kgjr.6224 3 ай бұрын
I rely wish your channel should grow because in todays world where other youtube channels as selling dreams this man is rely spreading real content and with huge amount of consistency
@krutikadave4534
@krutikadave4534 3 ай бұрын
maqsad string 😁 this channel is the OG of daily challenge leetcode!
@sanket3236
@sanket3236 3 ай бұрын
O(1) space approach : Suppose y > x in that case we have to remove first "ba" For that we can traverse the string with keeping count of b now whenever a occur & b's count > 0 we have found "ba" So increase the ans, decrease the count for b. Also we need to reset the b's count when any other char occur like bbbbx. Now then all the "ba" cases are done now we need to remove the "ab" cases, so for that we need all a that didn't make it in "ba". Basically all a for which there was no previous b to make a "ba" pattern, these all a can make ab pair so count all such a's and then increase the ans by min(cn(a), cn(b)) * min(x, y). This solution got accepted if anyone is looking for o(1) space approach
@iamnoob7593
@iamnoob7593 2 ай бұрын
Superb explanation , Thanks
@varunjain3947
@varunjain3947 3 ай бұрын
Thankyou so much bro amazing explanation💯
@akshaanshsrivastava9817
@akshaanshsrivastava9817 3 ай бұрын
Thanks Sir. These types of videos help me with intuition and approach..
@mayanktandon6942
@mayanktandon6942 3 ай бұрын
THIS IS LITERALLY BY FAR THE BEST F**ING EXPLANATION THERE WALKED THROUGH THE THOUGHT PROCESS FROM THE BEGINNER POV TO OPTIMIZATION , LOVED IT ❤
@Ayush37262
@Ayush37262 3 ай бұрын
Bro you are amazing 🙏
@IK-xk7ex
@IK-xk7ex 3 ай бұрын
Thank you! It's interesting technique with modifying the string in place. Hmm
@abhinavnarula7300
@abhinavnarula7300 3 ай бұрын
Is the second approach some kind of pattern or is it only applicable to this question only?
@ProtoS-c8x
@ProtoS-c8x 3 ай бұрын
25:52 - Overwriting
@naamnhibataunga5897
@naamnhibataunga5897 3 ай бұрын
this was my solution : class Solution { public: int point(string &s,string target, int p){ int total=0; string str=""; for(char c:s){ if(!str.empty() && string(1, str.back()) + c==target){ str.pop_back(); total+=p; } else{ str+=c; } } s=str; return total; } int maximumGain(string s, int x, int y) { string s1="ab", s2="ba"; if(y>x){ swap(s1,s2); swap(x,y); } return point(s,s1,x)+point(s,s2,y); } };
@vikasshokeen6044
@vikasshokeen6044 3 ай бұрын
Naah, that maqsad string got me 💀
@cenacr007
@cenacr007 3 ай бұрын
@sriramadithya9128
@sriramadithya9128 3 ай бұрын
Hi Aryan, I have been learning DSA for a month, and I am solving daily challenges in a leetcode, I used to see your videos for understanding a problem bro, Thanks for your work. But my question is when I see a problem I cannot solve it by myself. It feels like I am not improving anything 😞I always look for a solution. Did you have the same feeling when you were learning DSA, How did you overcome this?
@GalaxyStart62
@GalaxyStart62 3 ай бұрын
keep doing don't stop , it happens to all , once you have solved a good amount of problems like 200 + , it will come to your mind automatically.
@AnonymousAnonymous-ug8tp
@AnonymousAnonymous-ug8tp 3 ай бұрын
It is important to use pen and paper to properly understand the problems and dry run through the test cases to understand the nitty grittys of the problem. It will give you better insights to the problem and help to develop your own solution.
@sriramadithya9128
@sriramadithya9128 3 ай бұрын
@@GalaxyStart62 yea bro, I lost all my confidence today after seeing this problem. But as you said I need to solve more problems to get muscle memory and problem solving skills. Hope I will get soon.
@sriramadithya9128
@sriramadithya9128 3 ай бұрын
@@AnonymousAnonymous-ug8tp Yes bro I have been taking notes for every problem. First I will try to solve it without looking solution, But honestly I couldn't do it. I lost all my confidence today and messaged here. But I am not going to give up 🙂
@iamnottech8918
@iamnottech8918 3 ай бұрын
The catch is to do all concepts once then dpp or along with like after love or striver sheett
@theerock-e3i
@theerock-e3i 3 ай бұрын
please solve leetcode 913 cat and mouse problem
@theerock-e3i
@theerock-e3i 3 ай бұрын
please solve leetcode 913 cat and mouse
@kgjr.6224
@kgjr.6224 3 ай бұрын
commenting "anything"
@advaithmahendrakar
@advaithmahendrakar 3 ай бұрын
class Solution { public int maximumGain(String s, int x, int y) { Stack st = new Stack(); int ans =0; for(int i =0 ; i < s.length() ; i++){ System.out.println(st); if(s.charAt(i) == 'a'&& !st.isEmpty() && st.peek() == 'b' ){ if(y > x){ st.pop(); ans += y; System.out.println(ans); }else{ st.push(s.charAt(i)); } }else if(s.charAt(i) == 'b' && !st.isEmpty() && st.peek() == 'a'){ if(y > x){ st.push(s.charAt(i)); }else{ st.pop(); ans += x; System.out.println(ans + "x>"); } }else{ st.push(s.charAt(i)); } } while(!st.isEmpty()){ char ch = st.pop(); if(!st.isEmpty() && st.peek() == 'a' && ch == 'b'){ ans += x; }else if(!st.isEmpty() &&st.peek() == 'b' && ch == 'a'){ ans += y; } } return ans; } } Why is this solution wrong please anyone explain?
@DivyamGupta-e8q
@DivyamGupta-e8q 3 ай бұрын
maqsad mt bhulna bhaijaan....😁😁
@sibiranganath
@sibiranganath 3 ай бұрын
Just for algo
@GalaxyStart62
@GalaxyStart62 3 ай бұрын
sometimes i believe you exaggerate too much , that i loose my concentration , for me , it would be better if approach is point to point and concise. and you explain good no doubt.
2751. Robot Collisions | Stack | Sorting | Not Hard 🫡
19:30
Aryan Mittal
Рет қаралды 6 М.
啊?就这么水灵灵的穿上了?
00:18
一航1
Рет қаралды 53 МЛН
Maximum Score From Removing Substrings - Leetcode 1717 - Python
22:25
Learn JavaScript - Full Course for Beginners
3:26:43
freeCodeCamp.org
Рет қаралды 18 МЛН
If Your Tech Job is Comfortable, You're in Danger
20:57
Thriving Technologist
Рет қаралды 21 М.
Leetcode 1717. Maximum Score From Removing Substrings
10:39