Solution 4 for Scaler Topics Fortnightly Contest - 8
Learn via video course

DSA Problem Solving for Interviews using Java
by Jitender Punia
1000
4.9
This article is part of the Scaler Topics Fortnightly Contest - 8
Solution Approach
- We use Dynamic Programming to solve this problem.
- Let the states of DP be , where idx tells us which index we are currently at and waterLeft tells how much water is left with us to be filled in the rest of buckets.
- At an idx we have two possibilities, either to completely fill that bucket or to skip that bucket.
- Initially we will can to get the answer.
Time Complexity:-
Total Space Complexity:-