Even-tual Reduction Problem Code: EVENTUAL

#include <iostream>
using namespace std;

int main() {int t;
cin>>t;
while(t--)
{int n;int a[200]={0};int k=0;
    cin>>n;
 char str[n];
 cin>>str;
 for(int i=0;i<n;i++)
 {int c=(int)str[i];
 a[c]++;}
 for(int i=97;i<=122;i++)
 {if(a[i]%2!=0)
     k=-1;break;
 }
 if(k==-1)
 cout<<"NO"<<endl;
 else
 cout<<"YES"<<endl;
 
}
	// your code goes here
	return 0;
}

WHY AM I GETTING A WRONG ANSWE HERE?

It’s better to provide the submission link!

There are no braces in the if block so the break; statement always runs in the first iteration of the loop…

1 Like

i dont know about the question but this seems to your error if you dont give braces then if condition only checks the k-- but never break so.

{ 
    if(a[i]%2!=0)
       {
          k=-1;break;
       }
 }

maybe this solves your error.

1 Like

but once k is assigned value -1 then the absence of break statement doesnt matter as well. if once k is assigned -1 then we’ll have NO printed