What s wrong in my code as it fails in 2 test cases

I have written a code which fails in two test cases and passes in 1 kindly tell the error

Code is
#include
#include
using namespace std;
int main()
{
int n,j,i,l,p;
cin>>n;
int a[n],v[n];
int g=0;
while(g<n)
{
cin>>a[g];
g++;
}
for(i=0;i<n;i++)
{
v[i]=a[i];
}
sort(a,a+n);
gā€“;
while(g>=0)
{
if(a[g]==a[g-1])
{
break;
}
else
{
gā€“;
}
}
for(i=0;i<n;i++)
{
if(v[i]==a[g])
{

        break;
    }

}
for(j=0;j<n;j++)
{
    if(v[j]==a[g])
    {
        
         l=j;
    }

}
int area=(l-i+1)*a[g];

for(p=i;p<=l;p++)
{
    if(v[p]<a[g]|| v[p]==a[g])
    {  
        int c=area-v[p];
        area=c;
        
    }
    else
    {  
        area=area-a[g];
        
    }
}
cout<<area;

}

Hello @Ramitgoel,

  1. From next time share your code using Online Coding blocks IDE.
    The way you have send it is introducing many syntax errors to it.
    Steps:
    1.1. Paste your code there: https://ide.codingblocks.com/
    1.2. Save it there.
    1.3. Share the URL generated.

  2. Your code is not satisfying the test cases like:
    Example 1:
    6
    3 0 0 2 0 4
    Expected Output:
    10
    Your Output:
    0
    Example 2:
    12
    0 1 0 2 1 0 1 3 2 1 2 1
    Expected Output:
    6
    Your Output:
    5

Hope, this would help.
Give a like, if you are satisfied.

1 Like