My issue
include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int n,t;
cin>>t;
while(t–){
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
int s=0;
for(int i=n-1;i>0;i-=2){
s+=abs(a[i]-a[i-1]);
}
// cout<<abs(a[0]-a[1])<<endl;
cout<<s<<endl;
}
}
what’s going wrong with my code?
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int n,t;
cin>>t;
while(t--){
cin>>n;
int a[n];
for(int i=0;i<n;i++){
cin>>a[i];
}
int s=0;
for(int i=n-1;i>0;i-=2){
s+=abs(a[i]-a[i-1]);
}
// cout<<abs(a[0]-a[1])<<endl;
cout<<s<<endl;
}
}
Problem Link: Maximum Score Practice Coding Problem - CodeChef