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

Поделиться
HTML-код
  • Опубликовано: 3 авг 2024

Комментарии • 29

  • @ARYANMITTAL
    @ARYANMITTAL  23 дня назад +17

    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 🌚)

  • @mayanktandon6942
    @mayanktandon6942 22 дня назад +1

    THIS IS LITERALLY BY FAR THE BEST F**ING EXPLANATION THERE
    WALKED THROUGH THE THOUGHT PROCESS FROM THE BEGINNER POV TO OPTIMIZATION , LOVED IT ❤

  • @rev_krakken70
    @rev_krakken70 23 дня назад +9

    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

  • @krutikadave4534
    @krutikadave4534 22 дня назад +2

    maqsad string 😁 this channel is the OG of daily challenge leetcode!

  • @iamnoob7593
    @iamnoob7593 14 дней назад

    Superb explanation , Thanks

  • @varunjain3947
    @varunjain3947 22 дня назад

    Thankyou so much bro amazing explanation💯

  • @sanket3236
    @sanket3236 22 дня назад +1

    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

  • @kgjr.6224
    @kgjr.6224 22 дня назад

    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

  • @Ayush37262
    @Ayush37262 22 дня назад

    Bro you are amazing 🙏

  • @akshaanshsrivastava9817
    @akshaanshsrivastava9817 23 дня назад

    Thanks Sir. These types of videos help me with intuition and approach..

  • @vikasshokeen6044
    @vikasshokeen6044 23 дня назад +10

    Naah, that maqsad string got me 💀

  • @IK-xk7ex
    @IK-xk7ex 23 дня назад

    Thank you! It's interesting technique with modifying the string in place. Hmm

  • @cenacr007
    @cenacr007 22 дня назад

  • @naamnhibataunga5897
    @naamnhibataunga5897 23 дня назад +2

    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);
    }
    };

  • @user-gl1ef2ok1d
    @user-gl1ef2ok1d 22 дня назад

    25:52 - Overwriting

  • @abhinavnarula7300
    @abhinavnarula7300 22 дня назад

    Is the second approach some kind of pattern or is it only applicable to this question only?

  • @theerock-e3i
    @theerock-e3i 23 дня назад

    please solve leetcode 913 cat and mouse

  • @theerock-e3i
    @theerock-e3i 23 дня назад

    please solve leetcode 913 cat and mouse problem

  • @sriramadithya9128
    @sriramadithya9128 23 дня назад +1

    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 23 дня назад +2

      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 23 дня назад +1

      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 23 дня назад

      @@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 23 дня назад

      @@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 22 дня назад

      The catch is to do all concepts once then dpp or along with like after love or striver sheett

  • @advaithmahendrakar
    @advaithmahendrakar 22 дня назад

    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?

  • @sibiranganath
    @sibiranganath 23 дня назад

    Just for algo

  • @user-bf4xh7hp7n
    @user-bf4xh7hp7n 23 дня назад +2

    maqsad mt bhulna bhaijaan....😁😁

  • @kgjr.6224
    @kgjr.6224 22 дня назад

    commenting "anything"

  • @GalaxyStart62
    @GalaxyStart62 23 дня назад +5

    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.