Hi guys, please don’t worry if this qn seemed very hard. Actually this is based on Partition DP pattern. I didn’t mention this because i have not yet taught it in my channel. In my DP concepts playlist I will cover these topics. Dont worry, when I cover that topic, i will revisit this for sure and will also cover bottom up Thank you all ❤
Very Good explanation. many teachers put effort on solution, but you put effort on the explanation and that is why it was so good. I really understood the question and the solution with your explanation. the explanation was very good! keep it up bro!
You are the only guy who put all the efforts into the explanation. Code to fir humlog karlte hain. Watched some other videos since morning and all were just copy pasting the code without clear explanation. You are the best♥
First time a teacher making us realise it's okk that you can't do and this one question can't judge your ability ❤❤❤❤❤❤❤❤ really thanks from heart sir becoz i am among those who got demotivated after not able to solve ❤❤ thanks sir
I had seen this video once in 2023 when I came across this question for the first time and it made sense then. Now watching it again in 2024 when I came across this question as a leetcode daily problem. I wasn't able to recall the approach I had taken back then and had to watch the entire video. Not sure if I will be able to solve this if I encounter this problem again. Such is the difficulty of this problem, or my lack of understanding.
Very very hardest question till now that i encounter in DP while i have solved over 450+ problems including 65% medium & 13% hard problems then also to think in the direction of question solution is not that much easy to me without @Mazhar Imran khan bhaiyan, hats off to you!
This video is a game-changer! 🌟 The way you teach DSA is simply amazing. I struggled to understand the question before, but your clear explanations and examples made everything click. You’re truly one of the best teachers out there. Thank you for making such helpful content!
. Please note that, This topic is going to come with scratch in my DP concepts playlist. Actually this problem is based on partition dp pattern. I didn’t mention because i have not yet taught it in my channel. I promise i will revisit this qn when I teach Partition dp and will solve this qn again with 1) Recursion + memo 2) Bottom up ❤️❤️❤️
Hello.. Thank you for great explanation. Your explanation never made me feel it is a hard problem. However I would like to add something: We don't need an extra if (at line 17 of your code) because we are adding the equivalent if at line 10. Open for any criticism or suggestion. Thanks.
Sir isme lalach waale approach mein hamne solve(j,r) pe call kyu kiya jabki mujhe pata hai ki jo j pe character hai usi ko print kar raha hu main (as in ki pehle hi maine 'a' ke continuously character print kiye hai toh usime include kar lunga ) toh solve(j+1,r) ki cal nahi karenge ham?
because ham log uska cost pehle add nhi kiye hai so jo aage rahega usme se uska cost add kar lenge thats why we have started from j and not j+1 , becaue j par whi char hai jo l par tha aur jiska cost we havent added will be added when we do a recursive call for solve(j ,r). Hope this helps !!
very nice explaination just thinking the lalach wala tareeka is extremely hard. Thought i understand this one now but still i am not confident enough about the fact, that i will be able to solve similar questions, i guess the only thing in hand is practice.
Dont worry, In my DP concepts playlist I will cover these topics. This is actually based on Partition DP. Dont worry, when I cover that topic, i will revisit this for sure and will also cover bottom up
Amazing explanation bhaiya , the question is very good and particition dp as it is a difficult topic , but you made this question look very much intuitive. Eagerly waiting for your particition dp playlist . Kudos to you
Hi there, I know why many people could solve this in 30-40 minutes. Because they are already aware about Partition DP. Please see my pinned comment 😇🙏❤️ I promise you will be able to solve this. Just give me some time to complete Partition dp in my playlist 😇🙏
Excellent Explanation!! Thank you so much...but I didn't understand one part ....in lalach vali adjustment we can print last "ba" but what about the first "a" how it will get printed ..please explain
Sir remove boxes leetcode 546 question was asked in OA in cisco It was very similar to this .Plz try to upload its solution. Ty for all your efforts sir❤
Bhaiya samajh to aaya but jab thoda bada string le raha hu 5 length ki then uspe dry run karne mein kafi problem aa rhi hai aap pls bade test case pe run karke bata sakte ho kya? Kafi help hojayegi
Generally qns get dislikes because of poor problem statement Dont worry, in interviews, they clear the qns well and explain well if you dont get it. You can check for explanation in discuss sections else leave the qn if its too badly explained
Indeed. Please note that, This topic is going to come with scratch in my DP concepts playlist. Actually this problem is based on partition dp pattern. I didn’t mention because i have not yet taught it in my channel. I promise i will revisit this qn when I teach Partition dp and will solve this qn again with 1) Recursion + memo 2) Bottom up ❤️❤️❤️
Hi sir in this video for lalach case you have mentioned that we are tacking solve(i, j-1, s) + solve (j, r, s) instead of 1 + solve(i, j-1, s) + solve(j+1, r, s) so as per the your point of view both are same but if I take second one instead of first one than I am not getting right answer please explain me if anyone know about it
Thanks for the explanation. dimagh kharab kar diya tha is question nay and whats the difference between matric chain multiplication and partioning dp ?
Both refer to same pattern. I will cover this in full detail in my DP concepts playlist. And I am gonna revisit this qn again that time with recur memo as well as bottom up
Hello sir ,mujhe leetcode k problems video dekhne k baad hi smjh aata h . Data Structure implementation ho jta h but logic kabhi nhi aa ta h problem solving k liye. Uske liye kya karu please help
Hi there, Please cover DSA topic by topic. Fix one topic for a day, study it, solve easy qns, then medium qns. Skip hard as of now until you have practices easy mediums in a good number.
I am observing that in some OAs, tough qns are being asked. In such cases cp help. But many of my juniors and friends gave Amazon , Microsoft OAs and leetcode medium hard were enough for those qns. The main motive should be to first get clarity in each and every topic. Then start solving qns on those topics from easy -> Medium -> Hard -> expert
Dont worry, In my DP concepts playlist I will cover these topics. This is actually based on Partition DP. Dont worry, when I cover that topic, i will revisit this for sure and will also cover bottom up
Dont worry, In my DP concepts playlist I will cover these topics. This is actually based on Partition DP. Dont worry, when I cover that topic, i will revisit this for sure and will also cover bottom up
Can anyone help me memoize this recursive code.It is working but it i sgiving TLE at 17th test case. Please help me. class Solution { public: int solve(int i,string temp,string s) { if(s==temp) return 0; if(i>=s.length()) { return 1000000; } int minoperations=1000000; for(int start =i;start
Hi there, Apologies if it was not much clear. I will definitely improve more on that. However would you kindly share which part exactly you couldn’t get ?
@@codestorywithMIK i am not able to understand the explanations like how i,j ,l,r realated don't know. not able to make image of the solution or explanation in my mind
Noted guys I really appreciate your feedback. Please don’t worry. This topic is going to come with scratch in my DP concepts playlist. Actually this problem is based on partition dp pattern. I didn’t mention because i have not yet taught it in my channel. I promise i will revisit this qn when I teach Partition dp and will solve this qn again with 1) Recursion + memo 2) Bottom up ❤️❤️❤️
Hi guys, please don’t worry if this qn seemed very hard. Actually this is based on Partition DP pattern. I didn’t mention this because i have not yet taught it in my channel.
In my DP concepts playlist I will cover these topics.
Dont worry, when I cover that topic, i will revisit this for sure and will also cover bottom up
Thank you all ❤
bhaiyya please complete this topic
All the debates are over now. This guy is the ultimate best tutor of DSA on TH-cam. Hats off
Very Good explanation. many teachers put effort on solution, but you put effort on the explanation and that is why it was so good. I really understood the question and the solution with your explanation. the explanation was very good! keep it up bro!
It means a lot. Thank you so much ❤️🙏
💯
totally agree . This is a legit channel
++
You are the only guy who put all the efforts into the explanation. Code to fir humlog karlte hain.
Watched some other videos since morning and all were just copy pasting the code without clear explanation. You are the best♥
First time a teacher making us realise it's okk that you can't do and this one question can't judge your ability ❤❤❤❤❤❤❤❤ really thanks from heart sir becoz i am among those who got demotivated after not able to solve ❤❤ thanks sir
Thank you so much for watching ❤️😇
I had seen this video once in 2023 when I came across this question for the first time and it made sense then.
Now watching it again in 2024 when I came across this question as a leetcode daily problem. I wasn't able to recall the approach I had taken back then and had to watch the entire video.
Not sure if I will be able to solve this if I encounter this problem again.
Such is the difficulty of this problem, or my lack of understanding.
Very very hardest question till now that i encounter in DP while i have solved over 450+ problems including 65% medium & 13% hard problems then also to think in the direction of question solution is not that much easy to me without @Mazhar Imran khan bhaiyan, hats off to you!
This video is a game-changer! 🌟 The way you teach DSA is simply amazing. I struggled to understand the question before, but your clear explanations and examples made everything click. You’re truly one of the best teachers out there. Thank you for making such helpful content!
🙏❤️ This means a lot to me
No doubt :)
Literally the only video on youtube which explain this question with clarity 🙌👌🏻
A very very similar qn which can be solved using same code asked in CISCO Online Assessment few days ago - leetcode.com/problems/remove-boxes/
Beyond mere explanation, I appreciate how you've made it this intuitive!
Thanks for the motivation, it was much needed!
Keep up the good work sir!
.
Please note that, This topic is going to come with scratch in my DP concepts playlist.
Actually this problem is based on partition dp pattern. I didn’t mention because i have not yet taught it in my channel.
I promise i will revisit this qn when I teach Partition dp and will solve this qn again with
1) Recursion + memo
2) Bottom up
❤️❤️❤️
you are a legend. The effort you put in explanation and intuition building is unmatchable
Koi itna acha kaise explain kar sakta hai yaar.
I am short of words to describe his skill of teaching. L.E.G.E.N.D.DDDDDDDDDDDDDDDDDDD 💯
Hello.. Thank you for great explanation. Your explanation never made me feel it is a hard problem.
However I would like to add something:
We don't need an extra if (at line 17 of your code) because we are adding the equivalent if at line 10.
Open for any criticism or suggestion.
Thanks.
Was unable to understand the question even ....now it's clear
Thank you so much for watching ❤️😇
Yeah this one is quite tricky, didnt even see the repeating subproblems at first.
Bhaiya please continue with your dp concepts playlist, it's been incredibly helpful !
Couldnt we do 1+(i,j-1)+(j+1,r) ? if (j+1 out of bound then return 0)
Sir isme lalach waale approach mein hamne solve(j,r) pe call kyu kiya jabki mujhe pata hai ki jo j pe character hai usi ko print kar raha hu main (as in ki pehle hi maine 'a' ke continuously character print kiye hai toh usime include kar lunga ) toh solve(j+1,r) ki cal nahi karenge ham?
because ham log uska cost pehle add nhi kiye hai so jo aage rahega usme se uska cost add kar lenge thats why we have started from j and not j+1 , becaue j par whi char hai jo l par tha aur jiska cost we havent added will be added when we do a recursive call for solve(j ,r). Hope this helps !!
Aap bhagwan ho. Mai isi question ka solution samajhne ki koshish kar rha tha aur aapne daal diya.
Thank you so much for watching 😇❤️
Greaaaaaattttt sir....not even to understand the question in first go 😢...u r an absolute great teacher sir
Thanks a lot. Means so much 🙏❤️😇
ap GOD admi ho. or in new terms GOAT (greatest of all times :) )
this is also valid right -> 1 + solve(i,j-1) + solve(j+1,r)
Please MIK don't stop making these videos🩷
Great Explanation as always 👌🏻
Thank you so much.
Also, Please see my pinned comment 😇🙏❤️
Yes 👍🏻@@codestorywithMIK
sir whenever I feel stuck u saved me
Best explanation i could ever find
Means a lot 😇❤️
wow !!! thankyou sir !!! i really understooooood in one go!!! got confidence !! thankyou again
Thank you 🙏😇
very nice explaination just thinking the lalach wala tareeka is extremely hard. Thought i understand this one now but still i am not confident enough about the fact, that i will be able to solve similar questions, i guess the only thing in hand is practice.
Dont worry,
In my DP concepts playlist I will cover these topics. This is actually based on Partition DP.
Dont worry, when I cover that topic, i will revisit this for sure and will also cover bottom up
Superb explanations til now going top
Thank you so much 🙏❤️
Its a partation dp hard problem :-
my implmentation is :-
int n ;
int dp[102][102];
int solve(int i , int j , string s)
{
//base case
if(i==j) //length 1 string only 1 turn need
return 1;
if(dp[i][j] != -1)
return dp[i][j];
// for all other cases we need to do the partataion
// This is question of partation dp => aditya verma explanation
int minturn = INT_MAX;
for(int k = i ; k < j ; k++)
{
minturn = min(minturn , solve(i,k,s) + solve(k+1,j,s));
}
// 1 extra case is there if first and last char matches i.e i and j matches then
// minturn will be reduce by 1
if(s[i]==s[j])
return dp[i][j] = minturn-1;
return dp[i][j] = minturn;
}
int strangePrinter(string s) {
n = s.size();
if(n==1) return 1;
memset(dp,-1,sizeof(dp));
return solve(0,n-1,s);
Indeed ❤️
explain leetcode contest hard problems too , your explainations is very intuitive
Sure thing ❤️😇
Also, Please see my pinned comment 😇🙏❤️
Aaj ke leetcode contest ka 4th and 3rd questions ka bhi video bna do sir
Amazing explanation bhaiya , the question is very good and particition dp as it is a difficult topic , but you made this question look very much intuitive. Eagerly waiting for your particition dp playlist . Kudos to you
Thank you so much.
Partition dp coming soon in my DP Concepts and Qns playlist ❤️❤️❤️
Suggetion: Start making videos on Contest Questions,next day after contest is over .
amazing, can you give an example jisme basic se better result aayega ?
also please make the video on other approaches,
thank you...
Mere codeforces' expert friend ne ye ques khud se 40 min ke under solve kr liya😢
btw I did a slight optimisation in ur code, this one:
int greedy = INT_MAX;
for(int j=i; j
Hi there,
I know why many people could solve this in 30-40 minutes. Because they are already aware about Partition DP.
Please see my pinned comment 😇🙏❤️
I promise you will be able to solve this. Just give me some time to complete Partition dp in my playlist 😇🙏
Excellent Explanation!! Thank you so much...but I didn't understand one part ....in lalach vali adjustment we can print last "ba" but what about the first "a" how it will get printed ..please explain
it will get printed when you print the last a... you are smart enough to print all the previous 'a' to the current one
@@AnkitKumar-ge3jn Ok thank you...
Was a classic mcm type question
I will make it easy hits different ❤❤
Sir remove boxes leetcode 546 question was asked in OA in cisco
It was very similar to this .Plz try to upload its solution.
Ty for all your efforts sir❤
Sure thing.
Noted ❤️❤️❤️
Legend ho sir aap
Bhaiya samajh to aaya but jab thoda bada string le raha hu 5 length ki then uspe dry run karne mein kafi problem aa rhi hai aap pls bade test case pe run karke bata sakte ho kya? Kafi help hojayegi
Hey MIK Bhaiya!
Are LeetCode questions with a lot of downvotes worth solving?
I have the same question
Same qn
Same qn bhai
Generally qns get dislikes because of poor problem statement
Dont worry, in interviews, they clear the qns well and explain well if you dont get it. You can check for explanation in discuss sections else leave the qn if its too badly explained
NICE SUPER EXCELLENT MOTIVATED
dp questions are always interesting
Indeed.
Please note that, This topic is going to come with scratch in my DP concepts playlist.
Actually this problem is based on partition dp pattern. I didn’t mention because i have not yet taught it in my channel.
I promise i will revisit this qn when I teach Partition dp and will solve this qn again with
1) Recursion + memo
2) Bottom up
❤️❤️❤️
@@codestorywithMIK thank you. I have started watching the dp playlist 😄
❤️❤️❤️
back to this amazing Q and video after 1 year!!
Man you are the best.
please make a video on solving remove boxes question.
Hi sir in this video for lalach case you have mentioned that we are tacking solve(i, j-1, s) + solve (j, r, s) instead of 1 + solve(i, j-1, s) + solve(j+1, r, s) so as per the your point of view both are same but if I take second one instead of first one than I am not getting right answer please explain me if anyone know about it
Thanks a ton
Thanks for the explanation. dimagh kharab kar diya tha is question nay and whats the difference between matric chain multiplication and partioning dp ?
Both refer to same pattern.
I will cover this in full detail in my DP concepts playlist.
And I am gonna revisit this qn again that time with recur memo as well as bottom up
@@codestorywithMIK super. looking forward to it.
today's question...
How you are so good man❤
It means a lot Rajat.
Thank you so much 🙏❤️
Great
Bhaiya leetcode 1330 par bhi agar ho sake video bana dijiyega. Math aur greedy hai solution ekdum samajh nahi aa rha
Noted.
Will cover soon
very good sir
Thank you so much for watching ❤️😇
Thanks man!
Thank you so much for watching 🙏❤️
Hello sir ,mujhe leetcode k problems video dekhne k baad hi smjh aata h . Data Structure implementation ho jta h but logic kabhi nhi aa ta h problem solving k liye. Uske liye kya karu please help
Hi there,
Please cover DSA topic by topic.
Fix one topic for a day, study it, solve easy qns, then medium qns. Skip hard as of now until you have practices easy mediums in a good number.
15:26 , why are we not taking (j+1,r), to handle this .
super
Sir pls do contest qns also
This week’s Sunday Contest Qn-1 and 4
th-cam.com/video/2d1ALG8wwDc/w-d-xo.htmlsi=fAMNs8g1YmKgDe4e
❤️
❤❤
From where did YOU learnt this all?
bhaiya is cp necessory or good dsa enough for good compinies??.
Yes , to clear Online assessment independently you should do.
I am observing that in some OAs, tough qns are being asked. In such cases cp help.
But many of my juniors and friends gave Amazon , Microsoft OAs and leetcode medium hard were enough for those qns.
The main motive should be to first get clarity in each and every topic.
Then start solving qns on those topics from easy -> Medium -> Hard -> expert
This solution could be better....
class Solution {
int solveRec(int i, int j, string& s) {
if(i == j) return 1;
int ans = INT_MAX;
for(int k = i; k < j; k++) {
ans = min(ans, solveRec(i, k, s) + solveRec(k+1, j, s));
}
if(s[i] == s[j])
ans = ans - 1;
return ans;
}
int solveRec_Mem(int i, int j, string& s, vector& dp) {
if(i == j) return 1;
if(dp[i][j] != -1) return dp[i][j];
int ans = INT_MAX;
for(int k = i; k < j; k++) {
ans = min(ans, solveRec_Mem(i, k, s, dp) + solveRec_Mem(k+1, j, s, dp));
}
return dp[i][j] = (s[i]==s[j]) ? ans - 1 : ans;
}
public:
int strangePrinter(string s) {
int n = s.length();
// Recursive Approach
// return solveRec(0, n - 1, s);
// Recursion + Memoization
vector dp(n+1, vector(n+1, -1));
return solveRec_Mem(0, n - 1, s, dp);
}
};
Thank you so much for sharing ❤️😇
hey anyoune can explain how tbgtgb string take 4 step bcz i dry run think on it many times it take 5 step
t(0,0)+bbbbb(1,5)+ggg(2,4)+t(3,3)
@swapnilwalave1135 in the bracket, I have written (starting pos, ending pos) hope this helps
Thank you
How parition in 1,2,3,4 would result in ans 1,2,3,4 fir abaaaaa
i am the best❤
i dont have enough brain cells for this question 😢
Hello Anand,
Please see my pinned comment 😇🙏❤️
bhaiya seriously aaj ka question bilkul samajh nhi aaya🥲🥲🥲🥲
Same. I could only understand after watching this video 😢
Dont worry,
In my DP concepts playlist I will cover these topics. This is actually based on Partition DP.
Dont worry, when I cover that topic, i will revisit this for sure and will also cover bottom up
@@codestorywithMIK thanks bhaiya
bhaiya aapka naam kya hai??
For me it was difficult 😢😢
Dont worry,
In my DP concepts playlist I will cover these topics. This is actually based on Partition DP.
Dont worry, when I cover that topic, i will revisit this for sure and will also cover bottom up
Can anyone help me memoize this recursive code.It is working but it i sgiving TLE at 17th test case.
Please help me.
class Solution {
public:
int solve(int i,string temp,string s)
{
if(s==temp)
return 0;
if(i>=s.length())
{
return 1000000;
}
int minoperations=1000000;
for(int start =i;start
anyone solve this problem in java
thnx a lot brother , plz upload hard dp coders as much as possible
Sure thing
Thank you so much for watching ❤️😇
agar samaj nahi ata na to me is printer ko kude me fek deta yarr sachme. kya vahiyat printer hai😂
yaar aaj k samjh nhi aaya
Hi there,
Apologies if it was not much clear. I will definitely improve more on that. However would you kindly share which part exactly you couldn’t get ?
@@codestorywithMIK i am not able to understand the explanations like how i,j ,l,r realated don't know. not able to make image of the solution or explanation in my mind
same here🥲
Noted guys
I really appreciate your feedback.
Please don’t worry. This topic is going to come with scratch in my DP concepts playlist.
Actually this problem is based on partition dp pattern. I didn’t mention because i have not yet taught it in my channel.
I promise i will revisit this qn when I teach Partition dp and will solve this qn again with
1) Recursion + memo
2) Bottom up
❤️❤️❤️
@@codestorywithMIK thanks sir ♥️♥️
❤❤