Walls Coloring | GeeksforGeeks POTD 14 Feb 2023 | Dynamic Programming

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

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

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

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

    }

  • @atticusfinch6163
    @atticusfinch6163 ปีที่แล้ว +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!

  • @codingisfun-pranayharishch3001
    @codingisfun-pranayharishch3001 ปีที่แล้ว +2

    didi bohot time baad daali video...
    mai aapke videos pichle saal se dekh rha hu...
    ab regular rehna didi
    love your videos ❤️

  • @Idukhan-jj9kc
    @Idukhan-jj9kc ปีที่แล้ว

    Nice to hear u keep in touch ma'am

  • @reshmaparveen6679
    @reshmaparveen6679 ปีที่แล้ว

    Happy women's day 🎉🎉

  • @umangmalhotra1222
    @umangmalhotra1222 ปีที่แล้ว

    Nice Explainer Video ❤ . Want to see solution in Java as well.

  • @p25_rhythm70
    @p25_rhythm70 ปีที่แล้ว

    Nice explanation

  • @siddardhabhimany
    @siddardhabhimany ปีที่แล้ว

    Your DSA problem solving skills and your explanation is too good. Can you please drop your gfg profile ❤❤❤

  • @beonthego8725
    @beonthego8725 ปีที่แล้ว

    Happy Valentines day to you all 😊

  • @vibhashkumar5554
    @vibhashkumar5554 ปีที่แล้ว

    Please make video on median of subarrays (problem of the day gfg 18 March 2023).🙏

  • @venkata_mahesh
    @venkata_mahesh ปีที่แล้ว

    Great ! After many days.........

  • @udaysekharperuri5532
    @udaysekharperuri5532 ปีที่แล้ว

    Nice explanation ❤️

  • @babai2196
    @babai2196 ปีที่แล้ว

    Can u please make a dsa sheet for us to practice questions before placement!!!! That will be a great help

  • @Rajat_maurya
    @Rajat_maurya ปีที่แล้ว

    will you upload daily POTD ?

  • @reshmaparveen6679
    @reshmaparveen6679 ปีที่แล้ว

    Where are you now madam

  • @reshmaparveen6679
    @reshmaparveen6679 ปีที่แล้ว

    Ma'am where u gone
    Nice explanation will 🏀🏀🏀🏈

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

    you finally remember your password

  • @abhimanisangam79
    @abhimanisangam79 ปีที่แล้ว

    Java ?

  • @prateeksahni3993
    @prateeksahni3993 ปีที่แล้ว

    Ma’am, next problem one legged man ki uthana. Kaafi mushkil hai.

  • @rahulpoddar7732
    @rahulpoddar7732 ปีที่แล้ว

    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 👍