I had mostly done the problem…but for most the test cases answer is just the value of ans -1…
kindly correct my code
code link…
regards
I had mostly done the problem…but for most the test cases answer is just the value of ans -1…
kindly correct my code
code link…
regards
Hello @ManasxCOdE, your logic is almost correct but you didn’t consider multiple testcases. So also take the input for the no. of test cases and
for(int i=n-2;i>=0;i--)
{
if(a[i]>=a[i-1])
{
dec[i]=dec[i+1]+1;
}
else
{
dec[i]=1;
}
}
This part of code has some issue…
for(int i=n-2;i>=0;i--)
{
if(a[i+1]<=a[i])
{
dec[i]=dec[i+1]+1;
}
else
{
dec[i]=1;
}
}
Please see this we need to check the next element is smaller or equal to the previous element and you were doing something else.
Pls make this correct the code will work fine.
I had made the chnages that u mentioned but still not able to submit…
Here this is the required condition and you are using a[i-1] and a[i] values. Pls dry run this for better understanding.
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.