Help me in solving PRIMEREVERSE problem

My issue

check my code

My code

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
int t,l,k,h;
 cin>>t;
 while(t--)
 {long int n ;
     cin>>n ;
     char a[n+1];
     cin>>a;
     char b[n+1];
     cin>> b;
     int i ,j,l=0;
     if(j=='0'||j=='1')
     {k=0,h=0;
     for(i=0;a[i]!='\0';i++)
     {
     if(a[i]==j)
        { k++;}
     }
     for(i=0;b[i]!='\0';i++)
     {
     if( b[i]==j)
     {h++;}
     }
     if(k!=h)
     {l=1;}
     }
     if(l==0)
     {cout<<"yes\n";
     }else
     {cout<<"no\n";}
}
}

Problem Link: Prime Reversal Practice Coding Problem - CodeChef

@ayush907
plz refer the following code for better understanding of the logic

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n;
        cin>>n;
        string s,s1;
        cin>>s>>s1;
        int o=0,z=0;
        for(int i=0;i<n;i++)
        {
            if(s[i]=='1')
                o++;
            if(s1[i]=='1')
                o--;
            if(s[i]=='0')
                z++;
            if(s1[i]=='0')
                z--;
        }
        if(o==0&&z==0)
            cout<<"YES";
        else
            cout<<"NO";
        cout<<endl;
	}
	return 0;
}
1 Like