Question Link:- https://codeforces.com/contest/1520/problem/D
My Solution
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main()
{
fast
int t;
cin>>t;
while(t--)
{
ll n;
cin>>n;
ll count=0;
ll arr[n];
for(ll i=0;i<n;i++){
cin>>arr[i];
}
for(ll i=0;i<n;i++){
for(ll j=i+1;j<n;j++){
if(arr[j]-arr[i]==j-i){
count++;
}
}
}
cout<<count<<endl;
}
return 0;
}
I was getting an TLE on test 4 /5.
As Time limit was 2 seconds ,my code was O(n^2) hence it must have passed all the test cases .
Kindly Help(Correct my code).