My issue
Help
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
}
Problem Link: Sum of Modes Practice Coding Problem
Help
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
}
Problem Link: Sum of Modes Practice Coding Problem
include
#include<bits/stdc++.h>
define ll long long int
define mod 1000000007
using namespace std;
int main() {
cin.tie(0)->sync_with_stdio(false);
int t;cin>>t;
while(t–){
int n;cin>>n;
string s;cin>>s;
ll ans=n;
ans*=n+1;
ans/=2;
int a=0;
map<int,int>m;
m[0]++;
for(int i=0;i<n;i++){
if(s[i]==‘1’)a++;
else a–;
if(m.find(a)!=m.end()){
ans+=m[a];
}
m[a]++;
}
cout<<ans<<endl;
}
cerr << "Time : " << 1000 * ((double)clock()) / CLOCKS_PER_SEC << “ms” << endl;
return 0;
}
Try doing some failed test cases next time instead of just pasting the blank file