Target zero Problem (FAANG ) in arrays and String Section

I have solved the problem but all test cases have failed.
then i watched the solution video and it was same what i submitted. I tried again and again still all test cases are failing.What to do?

this is my code

#include
#include
#include
using namespace std;
vector targetzero(int n){
vectorv;
int n1=floor(n/2.0);
for(int i=1;i<=n1;i++){
v.push_back(i);
v.push_back((-1*i));

 }
 if(n%2==1){
     v.push_back(0);
 }
 return v;

}
int main(){
int n;
cin>>n;
vectorans;

 ans=targetzero(n);
 for(int i=0;i<ans.size();i++){
     cout<<ans[i]<<" ";
 }
 }

@vdeepu028 multiple correct solutions are possible for this question but for now it is not done in cb so your output should be specific as per testcases. so in your code just display negative then positive
like now your o/p 1 -1 2 -2 0 but ans -1 1 -2 2 0 here corrected


dont forget to hit like and mark resolved if cleared :smiley:

1 Like

Thanks for quick reply it helped…