Leetcode 2742 Painting the Walls
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...
Vey Well Explained
Thank you!!
nice explanatory video
Thank you
Telegram Community Links:
t.me/+FieKB7Ds6j02Y2Y1
t.me/+JU-ZF-oDjX4xYjBl
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!!!
Similar Problems:
leetcode.com/problems/partition-equal-subset-sum/
leetcode.com/problems/target-sum/
leetcode.com/problems/coin-change/
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];
}😢🎉😂❤