Problem with code logic

So what i understud is dp[i]= min(dp[i-1],dp[i-2],dp[i-3])
Is this right? So i need to keep summing them ?
dp[i] will store total minimum sum upto that point ?

Hey @pranjalarora98
Yes its almost correct

Realtion is
dp[i] = min({ dp[i-1] , dp[i-2] , dp[i-3] } ) + a[i];

Just 1 issue i had in undesrtanding.
The school’s rules say that no student can go three days in a row without any SUPW duty.

This is written so it means that every continious 3 days atleast 1 student should be there? They can be 2 or 3 also so we have to find minimum whatever included is it like this?

3 2 1 1 2 3 1 3 2 1

if this is the data then that means
Sorry these are minutes

Now this means that nikhil have to assign himself a duty without breaking that 3 day rule

And suppose i am writing base case so for dp[0]=arr[i]
dp[1] should be arr[0] + arr[1] coz we can select 2 right?
and dp2 should be max of arr0+arr1,arr1+arr2,arr0+arr2

is this fine?for base cases

Wait let me reread the question :slight_smile:
I think I misunderstood it maybe

Base case is
dp[1] = a[1];
dp[2] = min(a[2],a[1]);
dp[3] = min(a[2],a[1],a[3]);

Because only 1 day he have to work
if 2 days then he will not work on either first day or 2nd day
if 3 days he will on any of the first 3 days

The school’s rules say that no student can go three days in a row without any SUPW duty.
So it means that atleast 1 should be there from every continious 3 right? there can be 2 or there can be 3 also?

But we have to minimize so we will be seeing only 1 of the minimum ?

Yes correct from what I am understanding u are saying

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.