My issue
why this solution is failing can you please find the mistake.<3
My code
//Radhe Radhe
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const ll M = 998244353;
ll add(ll x, ll y) { return (x%M + y%M)%M; }
ll sub(ll x, ll y) { return (x%M - y%M + M)%M;}
ll mul(ll x, ll y) { return (x%M * y%M)%M; }
void print(vector<ll>v1){
for(auto x:v1){cout<<x<<" ";}
cout<<endl;}
ll binexp(ll a,ll b){
ll res = 1;
while(b){
if(b&1)res = ((res%M)*(a%M)%M);
a = ((a%M)*(a%M)%M);
b>>=1LL;
}
return res%M;
}
void Radhe(){
ll t;
cin>>t;
while(t--){
ll n;
cin>>n;
vector<int>v1(n);
for(int i=0;i<n;i++){
cin>>v1[i];
}
vector<ll>ans;
for(int i=0;i<n;i++){
int cnt = 1;
while(i<n-1 && v1[i]>v1[i+1]){
cnt++;
i++;
}
while(i<n-1 && v1[i]<v1[i+1]){
cnt++;
i++;
}
ans.push_back(cnt);
}
ll res = 0;
res+=ans.size()-1;
for(auto x:ans){
// cout<<x<<" ";
res += x*(x+1)/2;
}
// cout<<endl;
cout<<res<<endl;
}
}
int main(){
Radhe();
return 0;
}
Problem Link: Weird Subarrays Practice Coding Problem - CodeChef