SUbmission status : Time limit exceed
#include <stdio.h>
#include <stdbool.h>
bool maxPresent(long int arr[],long n,long max);
int main()
{
int t;
scanf(“%d”,&t);
while(t–)
{
long int n,sweetValue[100000],counter=0;
scanf(“%ld”,&n);
long max=0;
for(long int i=0;i<n;i++)
{
scanf(“%ld”,&sweetValue[i]);
if(sweetValue[i]>max)
max=sweetValue[i];
}
bool canShift = maxPresent(sweetValue,n,max);
if(canShift==true)
{
long int tempArray[100000]; //assigning last value to the first index...
for(int i=0;i<n/2;i++) //assigning rest of the value to the tempArray...
{
tempArray[0]=sweetValue[n-1];
for(int j=1;j<n;j++)
{
tempArray[j] = sweetValue[j-1];
}
canShift = maxPresent(tempArray,n,max); //check after shit !st half has tha max value or not
if(canShift==true)
continue;
else
counter++;
}
}
printf("%ld\n",counter);
}
return 0;
}
bool maxPresent(long int arr[],long n,long max)
{
bool flag=false;
for(int i=0;i<n/2;i++)
{
if(arr[i]==max)
{
flag = true;
break;
}
}
return flag;
}
Home » Compete » March Cook-Off 2020 Division 2 » Box of Chocolates