Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Subarray with 0 sum
#include<bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int n;cin>>n; vector<int>v(n); for(int i=0;i<n;i++) cin>>v[i]; vector<int>pref(n); pref[0]=v[0]; unordered_map<int,int>u; u[pref[0]]++; for(int i=1;i<n;i++) { pref[i]=pref[i-1]+v[i]; u[pref[i]]++; } int f=0; for(int i=0;i<n;i++) { if(u[pref[i]]>1) { f++; break; } } if(u[0]) { f++; } if(f==0) { cout<<"No"<<endl; } else { cout<<"Yes"<<endl; } } }
run
|
edit
|
history
|
help
0
Stream11
introduction c-types
Trapping rain water problem
Goooood
g++ -Wall *.cpp -o aco; ./aco.
Base conversion
copy_30-Seconds-of-C++
csv parser
Simulare 2022
TemplateRemove