Leetcode 2742 Painting the Walls

Sdílet
Vložit
  • čas přidán 12. 10. 2023
  • Solution to leetcode problem 2742. Painting the Walls
    I have used Dynamic Programming (DP) to solve this problem.
    Telegram Links:
    t.me/+FieKB7Ds6j02Y2Y1
    t.me/+JU-ZF-oDjX4xYjBl
    Problem Link: leetcode.com/problems/paintin...
    Solution Link: leetcode.com/problems/paintin...

Komentáře • 8

  • @user-zw5rz9vf8k
    @user-zw5rz9vf8k Před 9 měsíci +2

    Vey Well Explained

  • @kshitijgarg2609
    @kshitijgarg2609 Před 9 měsíci +1

    nice explanatory video

  • @c0de_sutra
    @c0de_sutra  Před 9 měsíci

    Telegram Community Links:
    t.me/+FieKB7Ds6j02Y2Y1
    t.me/+JU-ZF-oDjX4xYjBl

  • @tasneemayham974
    @tasneemayham974 Před 9 měsíci

    Sir, I thought about this problem like this: If I add up the totalTime and start with that: f(n,totalTime, T). If I went for not_take, totalTime will decrease by one and if I went for take, totalTime will increase by time[i]. If totalTime is greater than the start(T) then return 0 else return 1e9. Hence the dp will be [n+1][2*totalTime+1]. But it gives Memory Limit Exceeded. If I use your way which is [n][n+1], it will work. Mr. how should I know this is the correct way to solve starting from recursion?
    Thank you for your amazing videos bhaiya!!!

  • @c0de_sutra
    @c0de_sutra  Před 9 měsíci

    Similar Problems:
    leetcode.com/problems/partition-equal-subset-sum/
    leetcode.com/problems/target-sum/
    leetcode.com/problems/coin-change/

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 Před 9 měsíci

    public int paintWalls ( int []cost,int[]time){
    int k=500000000;
    int n=cost.length;
    int []dp=new int [n+1];
    Arrays.fill (dp,k);
    dp[0]=0;
    for(int i=0;i0;--walls)
    dp[walls]=Math.min (dp[walls],dp[Math.max (walls-time[i]-1,0)]+cost [i];
    return dp[n];
    }😢🎉😂❤