vectordp; int minCost(vector &colors, int N) { // Write your code here.
dp.resize(N, vector(4,-1)); return fnc(colors, N, 0, 3);
//0 ->pink, 1->black. 2 ->yellow }
int fnc(vector &colors, int N, int i, int prev) { if(i==colors.size()) { return 0; } int pink =INT_MAX; int black =INT_MAX; int yellow = INT_MAX; if(dp[i][prev]!=-1)return dp[i][prev]; if(prev!=0) { pink = colors[i][0]+fnc(colors, N, i+1, 0); }
if(prev!=1) { black = colors[i][1] +fnc(colors, N, i+1,1); }
I cannot express just how grateful I feel for your videos, if there's a video of yours on a certain topic I know it's going to be a cakewalk. Just a suggestion please solve more questions from the striver's sde sheet as most people do those questions for their interview preparations. Thank you so much for what you're doing!
Time Complexity - >O(N)
class Solution{
public:
vectordp;
int minCost(vector &colors, int N) {
// Write your code here.
dp.resize(N, vector(4,-1));
return fnc(colors, N, 0, 3);
//0 ->pink, 1->black. 2 ->yellow
}
int fnc(vector &colors, int N, int i, int prev)
{
if(i==colors.size())
{
return 0;
}
int pink =INT_MAX;
int black =INT_MAX;
int yellow = INT_MAX;
if(dp[i][prev]!=-1)return dp[i][prev];
if(prev!=0)
{
pink = colors[i][0]+fnc(colors, N, i+1, 0);
}
if(prev!=1)
{
black = colors[i][1] +fnc(colors, N, i+1,1);
}
if(prev!=2)
{
yellow = colors[i][2] + fnc(colors,N,i+1,2);
}
return dp[i][prev]= min(pink,min(black,yellow));
}
I cannot express just how grateful I feel for your videos, if there's a video of yours on a certain topic I know it's going to be a cakewalk. Just a suggestion please solve more questions from the striver's sde sheet as most people do those questions for their interview preparations. Thank you so much for what you're doing!
didi bohot time baad daali video...
mai aapke videos pichle saal se dekh rha hu...
ab regular rehna didi
love your videos ❤️
Nice to hear u keep in touch ma'am
Happy women's day 🎉🎉
Nice Explainer Video ❤ . Want to see solution in Java as well.
Nice explanation
Your DSA problem solving skills and your explanation is too good. Can you please drop your gfg profile ❤❤❤
Happy Valentines day to you all 😊
Please make video on median of subarrays (problem of the day gfg 18 March 2023).🙏
Great ! After many days.........
Nice explanation ❤️
Can u please make a dsa sheet for us to practice questions before placement!!!! That will be a great help
will you upload daily POTD ?
Where are you now madam
Ma'am where u gone
Nice explanation will 🏀🏀🏀🏈
you finally remember your password
Hahaha nice one🤣🤣
Java ?
Ma’am, next problem one legged man ki uthana. Kaafi mushkil hai.
Thumbnail wala photo change kar dijye not acha nhi lag rha hai . Half photo daliye jyada attractive lagega or usse jyada views bhi aayega . Wase content tho bahut acha hai aapka 👍