I tried to solve this problem : Lunchtime | CodeChef
so initially I went with the Bruteforce approach
here’s my code
#include <iostream>
using namespace std;
int main() {
int t;
cin>>t;
for(int i=0;i<t;i++){
int n;
cin>>n;
int a[n];
for(int j=0;j<n;j++){
cin>>a[j];
}
for(int j=0;j<n;j++){
int count=0;
for(int k=j-1;k>=0;k--){
if(a[k]>a[j]){
break;
}
else if(a[k]==a[j]){
count++;
}
}
for(int k=j+1;k<n;k++){
if(a[k]>a[j]){
break;
}
else if(a[k]==a[j]){
count++;
}
}
cout<<count<<" ";
}
}
return 0;
}
and It worked I got 100% score but I think that this code will exceed the time limit and also I used here int instead of long long for making an array where the value of the elements of an array could be up to 10^9 but still, this code worked. Can some please explain to me how did that happen?