My issue
//Determine the number of ways to place and push the ball so that all walls are destroyed…
it has asked this right???
but why the array [1,2,0,10] why we cant destroy this hwole array in 8 ways…i 1 ways it will become [0,0,0,7] now in remaining 7 ways 7 ways he can place the ball and destriy the 7…if 7 is not the right answer…i submiteed the accepted solution code’s…for this testcase it was giving output as 0 why??
My code
include <bits/stdc++.h>
using namespace std;
void solve(vector v){
int n=v.size();
int s1=0,s2=0;
for(int i=0;i<n;i++){
s2+=v[i];
}
int count=0;
for(int i=0;i<n;i++){
s1+=v[i];
s2-=v[i];
if(v[i]==0&&(s1==s2+1||s2==s1+1)){
count++;
}
else if(v[i]==0&&s1==s2){
count+=2;
}
}
cout<<count<<endl;
}
int main() {
int t,l=0;
cin>>t;
vector<vector> v(t);
while(t–){
int n;
cin>>n;
for(int i=0;i<n;i++){
int x;
cin>>x;
v[l].push_back(x);
}
l++;
}
for(int i=0;i<l;i++){
solve(v[i]);
}
}
Problem Link: Bouncing Ball Practice Coding Problem