The code is as follows: The link to the question is : Two Strings
#include <bits/stdc++.h>
using namespace std;
// Complete the twoStrings function below.
string twoStrings(string s1, string s2)
{
long long int i,j;
long long int m=s1.length();
long long int n=s2.length();
long long int dp[m+1][n+1];
for(i=0;i<=m;i++)
{
for(j=0;j<=n;j++)
dp[i][j]=0;
}
int count=0;
for(i=0;i<=m;i++)
{
for(j=0;j<=n;j++)
{
if(i==0||j==0)
dp[i][j]=0;
else if (s1[i-1]==s2[j-1])
{
dp[i][j]++;
count++;
}
}
}
if(count>0)
{
return "YES";
}
else
{
return "NO";
}
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
int q;
cin >> q;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
for (int q_itr = 0; q_itr < q; q_itr++) {
string s1;
getline(cin, s1);
string s2;
getline(cin, s2);
string result = twoStrings(s1, s2);
fout << result << "\n";
}
fout.close();
return 0;
}
It works perfectly for 6 out of 9 test cases. i don't think time is the problem here. it shows segmentation fault but doesn't elaborate on what actually the problem is. Any help would be appreciated. I can't figure out what the problem is