My issue
#include<bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t–){
string a,b;
int c=0;
cin>>a>>b;
int n=a.length();
int m = b.length();
sort(a.begin(),a.end());
sort(b.begin(),b.end());
for(int i=0,j=0;i<n,j<m;i++,j++){
if(a[i]==b[j])
c++;
}
cout<<c<<endl;
}
return 0;
}
Please help me to detect the error in the code. Sample test cases are showing correct output but may be some hidden test cases showing incorrect result.
My code
#include<bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t--){
string a,b;
int c=0;
cin>>a>>b;
int n=a.length();
int m = b.length();
sort(a.begin(),a.end());
sort(b.begin(),b.end());
for(int i=0,j=0;i<n,j<m;i++,j++){
if(a[i]==b[j])
c++;
}
cout<<c<<endl;
}
return 0;
}
Problem Link: Longest Common Pattern Practice Coding Problem - CodeChef