Remove Palindromic Subsequences | Live Coding with Explanation | Leetcode - 1332

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 พ.ย. 2024

ความคิดเห็น • 19

  • @AlgorithmsMadeEasy
    @AlgorithmsMadeEasy  3 ปีที่แล้ว

    We hope you all are enjoying our videos!!! Don't forget to leave a comment!!! Please like the video to support us!!!
    Questions you might like:
    ✅✅✅[ Tree Data Structure ] : th-cam.com/play/PLJtzaiEpVo2zx-rCqLMmcFEpZw1UpGWls.html
    ✅✅✅[ Graphs Data Structure ] : th-cam.com/play/PLJtzaiEpVo2xg89cZzZCHqX03a1Vb6w7C.html
    ✅✅✅[ January Leetcoding Challenge ] : th-cam.com/play/PLJtzaiEpVo2wCalBcRcNjXQ0C6ku3dRkn.html
    ✅✅✅[ December Leetcoding Challenge ] : th-cam.com/play/PLJtzaiEpVo2xo8OdPZxrpybGR8FmzZpCA.html
    ✅✅✅[ November Leetcoding Challenge ] : th-cam.com/play/PLJtzaiEpVo2yMYz5RPH6pfB0wNnwWsK7e.html
    ✅✅✅[ August Leetcoding Challenge ] : th-cam.com/play/PLJtzaiEpVo2xu4h0gYQzvOMboclK_pZMe.html
    ✅✅✅July Leetcoding challenges: th-cam.com/play/PLJtzaiEpVo2wrUwkvexbC-vbUqVIy7qC-.html
    ✅✅✅June Leetcoding challenges: th-cam.com/play/PLJtzaiEpVo2xIfpptnCvUtKrUcod2zAKG.html
    ✅✅✅May Leetcoding challenges: th-cam.com/play/PLJtzaiEpVo2wRmUCq96zsUwOVD6p66K9e.html
    ✅✅✅Cracking the Coding Interview - Unique String: th-cam.com/play/PLJtzaiEpVo2xXf4LZb3y_BopOnLC1L4mE.html
    Struggling in a question??
    Leave in a comment and we will make a video!!!🙂🙂🙂

  • @MrACrazyHobo
    @MrACrazyHobo 3 ปีที่แล้ว +6

    Oh my god I just realized - we are removing palindromic SUBSEQUENCES! NOT SUBSTRING! Thats how you can get a maximum of 2 as your answer
    (remove all a's, then remove all b's)

  • @phaniadityach2317
    @phaniadityach2317 2 ปีที่แล้ว

    can you please tell if there a way to find the number of ways in case of a string consisting of different characters? i.e, more than 2 distinct characters?

  • @pironobcoding
    @pironobcoding 2 ปีที่แล้ว +1

    after seeing this solution my mind has been blown

  • @bharatbhatia6000
    @bharatbhatia6000 3 ปีที่แล้ว +4

    What if string is "baabbaaaba"
    How will answer be 2 for this please explain.
    I didn't get it

    • @ForCodingInterview
      @ForCodingInterview 3 ปีที่แล้ว

      b'aabbaa'aba -> baba -> ""

    • @bharatbhatia6000
      @bharatbhatia6000 3 ปีที่แล้ว +2

      @@ForCodingInterview ok fine
      But i still didn't get how the max result can be 2. Can you explain briefly

    • @RahulGupta-qo7fi
      @RahulGupta-qo7fi 3 ปีที่แล้ว +2

      @@bharatbhatia6000 acc to Question, you can skip any number of character in string. As we have only 2 type a &b. So if we skip all a or all b , at max we have to do 2 steps. If all char are same means whole string is palindrome so , ans will be 1 . And in case of empty string, ans will be 0.

    • @sudharshanchakravarthy7199
      @sudharshanchakravarthy7199 3 ปีที่แล้ว +2

      @@ForCodingInterview how is "baba" a palindrome?

    • @bharatbhatia6000
      @bharatbhatia6000 3 ปีที่แล้ว +1

      @@sudharshanchakravarthy7199 yes good point..

  • @hereweare644
    @hereweare644 2 ปีที่แล้ว

    As you said 2 will be the maximum answer, but it doesn't suit for 'aababbaaba'. It takes 3 steps. If I was wrong please let me know.

    • @AlgorithmsMadeEasy
      @AlgorithmsMadeEasy  2 ปีที่แล้ว

      It will be maximum 2 because the question ask us to find subsequence.
      Now the difference between substring and subsequence is that the substring is a continuous set of character while the same is not the case in subsequence. So i can just take all 'a' at once and then all 'b' the second time.
      Hope it clears that up.

  • @CRamPrasannaCV
    @CRamPrasannaCV 3 ปีที่แล้ว +1

    Understood :-)

  • @bharathkalyans
    @bharathkalyans 2 ปีที่แล้ว

    I approached this way, but could only pass 19/38 TC.🫡
    private int solve(String s, int low, int high){
    if(low > high) return s.length();
    if(low == high) return 1;
    if(low + 1 == high) return s.charAt(low) == s.charAt(high) ? 1 : 2;
    if(s.charAt(low) == s.charAt(high))
    return solve(s, low + 1, high - 1);
    return Math.min(solve(s, low, high - 1), solve(s, low + 1, high)) + 1;
    }