I think i have covered all the edge cases please look into my code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main () {
ll n;cin>>n;
ll a[n];
for(ll i=0;i<n;i++)cin>>a[i];
if(n==1){
cout<<a[0]<<endl;
}
else if(n==2){
cout<<min(a[0],a[1])<<endl;
}
else {
ll dp[n];
for(ll i=0;i<n;i++){
if(i<=2 )dp[i]=a[i];
else{
dp[i]=a[i]+min(dp[i-1],min(dp[i-2],dp[i-3]));
}
}
cout<<min(dp[n-1],min(dp[n-2],dp[n-3]))<<endl;
}
return 0;
}
Whats the edge case?
Please have a look at this very short code.
Its very easy to understand,you’ll get your mistake.
your code also gave wrong ans on 1 test case in the DP course
and btw your solution will give runtime error/sementfault if n==1 or n==2
I am unable to submit the code for now.
Which test case number are you failing?
I shall show you the inputs and expected outputs, so that you can compare your answer and findout for now
TESTCASE # 1 : wrong-answer (Time: 0 s)
TESTCASE # 2 : correct (Time: 0.24 s)
TESTCASE # 3 : correct (Time: 0.32 s)
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.
Hi , yes you are absolutely right. There is an issue with the test case.
Our tech team is working towards it, we will remove that bug soon.