- #1
SlurrerOfSpeech
- 141
- 11
What I have is
Which is passing the basic test cases of mine and the sites's:
But it is failing this one
and I can't figure out why because the inputs are too big for me to see what's going on. Mine is undercalculating (10).
Code:
/// <summary>
/// Provides a solution to the Common Child string problem
/// https://www.hackerrank.com/challenges/common-child/problem
/// </summary>
public static class CommonChild
{
public static int Solve(string first, string second)
{
int max = 0;
for (int i = 0; i < first.Length; ++i)
{
int current = 0;
for (int j = i, k = 0; j < first.Length; ++j)
{
int m = k;
bool found = false;
for (; k < second.Length && !found; ++k)
{
if (first[j] == second[k])
{
current += 1;
found = true;
}
}
if (!found)
{
k = m;
}
}
if (current > max)
{
max = current;
}
}
return max;
}
}
Which is passing the basic test cases of mine and the sites's:
Code:
[TestMethod]
public void SampleTest0()
{
ExecuteTest(first: "HARRY", second: "SALLY", expected: 2);
}
[TestMethod]
public void SampleTest1()
{
ExecuteTest(first: "AA", second: "BB", expected: 0);
}
[TestMethod]
public void SampleTest2()
{
ExecuteTest(first: "SHINCHAN", second: "NOHARAAA", expected: 3);
}
[TestMethod]
public void SampleTest3()
{
ExecuteTest(first: "ABCDEF", second: "FBDAMN", expected: 2);
}
[TestMethod]
public void MyTest0()
{
ExecuteTest(first: "", second: "", expected: 0);
}
[TestMethod]
public void MyTest1()
{
ExecuteTest(first: "", second: "A", expected: 0);
}
[TestMethod]
public void MyTest2()
{
ExecuteTest(first: "A", second: "A", expected: 1);
}
[TestMethod]
public void MyTest3()
{
ExecuteTest(first: "A", second: "B", expected: 0);
}
[TestMethod]
public void MyTest4()
{
ExecuteTest(first: "A", second: "AB", expected: 1);
}
[TestMethod]
public void MyTest5()
{
ExecuteTest(first: "A", second: "BA", expected: 1);
}
[TestMethod]
public void MyTest6()
{
ExecuteTest(first: "AB", second: "BA", expected: 1);
}
[TestMethod]
public void MyTest7()
{
ExecuteTest(first: "AB", second: "AB", expected: 2);
}
[TestMethod]
public void MyTest8()
{
ExecuteTest(first: "AC", second: "ABC", expected: 2);
}
[TestMethod]
public void MyTest9()
{
ExecuteTest(first: "AC", second: "ABCD", expected: 2);
}
[TestMethod]
public void MyTest10()
{
ExecuteTest(first: "ACE", second: "ABCDEE", expected: 3);
}
[TestMethod]
public void MyTest11()
{
ExecuteTest(first: "ACEF", second: "ABCDEE", expected: 3);
}
[TestMethod]
public void MyTest12()
{
ExecuteTest(first: "ACEJJKLMNPST", second: "ABCDEEGHHHIPQRRS", expected: 5);
}
[TestMethod]
public void MyTest13()
{
ExecuteTest(first: "ACEF", second: "BCDEEA", expected: 2);
}
[TestMethod]
public void MyTest14()
{
ExecuteTest(first: "WYZXY", second: "YOOX", expected: 2);
}
[TestMethod]
public void MyTest15()
{
ExecuteTest(first: "XXXXXXYXXX", second: "XYXXXXXXXX", expected: 9);
}
But it is failing this one
Code:
[TestMethod]
public void TestCase1()
{
ExecuteTest
(
first: "WEWOUCUIDGCGTRMEZEPXZFEJWISRSBBSYXAYDFEJJDLEBVHHKS",
second: "FDAGCXGKCTKWNECHMRXZWMLRYUCOCZHJRRJBOAJOQJZZVUYXIC",
expected: 15
);
}
and I can't figure out why because the inputs are too big for me to see what's going on. Mine is undercalculating (10).