My issue
what’s wrong with this as i’m using brute force approach sliding window and its not giving correct
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t; cin>>t;
while(t--){
long long int n;cin>>n;
vector<long long int>v(n);
for(long long int &i:v) cin>>i;
long long int s = 0,b=0;
for(int i=0;i<n-2;i++){
long long int c = 0;
for(int j=0;j<3;j++){
s+=v[i+j];
}if(s%3!=0) {
v[i+2]+=3-s%3;
c+=3-s%3;
}b+=c;
s=0;
}
cout<<b<<endl;
// for(auto i:v){
// cout<<i<<" ";
// }cout<<endl;
}
}
Problem Link: Segment Three Practice Coding Problem - CodeChef