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!!!🙂🙂🙂
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)
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?
@@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.
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.
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!!!🙂🙂🙂
What if the string is "baabbaaaba"? Good question by @bharat
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)
Rightly said!! 😊
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?
after seeing this solution my mind has been blown
Thanks
What if string is "baabbaaaba"
How will answer be 2 for this please explain.
I didn't get it
b'aabbaa'aba -> baba -> ""
@@ForCodingInterview ok fine
But i still didn't get how the max result can be 2. Can you explain briefly
@@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.
@@ForCodingInterview how is "baba" a palindrome?
@@sudharshanchakravarthy7199 yes good point..
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.
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.
Understood :-)
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;
}