CROSBLK - Editorial

Thank you so much bro

i passed that testcase it still fails
https://www.codechef.com/viewsolution/50434891

No bro 2 is the correct answer.

1 Like

O yeah 2 is correct sorry , my bad .
And about the error , i am not able to debug it . You may ask some experienced person .

oh thanks for your effort

1 Like

hey buddy can you find which test case is failing in my program thanks
https://www.codechef.com/viewsolution/50434891

exact same approach even WA kindly see …
#include

using namespace std;
void answer(int a[],int n)
{
int count=0;
int maxi=a[n-1];

int i=n-1;
while(i>=0)
{

     if(maxi<a[i])
     {
         
         maxi=a[i];
         count++;
     }
     i--;
      
}
if(maxi==a[0])
cout<<count<<endl;
else 
cout<<-1<<endl;

}

int main()
{
int t;
cin>>t;
while(t–)
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{

    cin>>a[i];
    }
    answer(a,n);
}

}

why my code giving wa
#include

using namespace std;
void answer(int a[],int n)
{
int count=0;
int maxi=a[n-1];

int i=n-1;
while(i>=0)
{

     if(maxi<a[i])
     {
         
         maxi=a[i];
         count++;
     }
     i--;
      
}
if(maxi==a[0])
cout<<count<<endl;
else 
cout<<-1<<endl;

}

int main()
{
int t;
cin>>t;
while(t–)
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{

    cin>>a[i];
    }
    answer(a,n);
}

}