public boolean prefixAgain(String str, int n) {
String strNew = str.substring(0, n - 1);
int len = str.length();
String strLaterHalf = str.substring(n, len);
if (strLaterHalf.contains(strNew)) {
return true;
} else {
return false;
}
}
I am getting below resultExpected Run
prefixAgain("abXYabc", 1) → true true OK
prefixAgain("abXYabc", 2) → true true OK
prefixAgain("abXYabc", 3) → false true X
prefixAgain("xyzxyxyxy", 2) → true true OK
prefixAgain("xyzxyxyxy", 3) → false true X
prefixAgain("Hi12345Hi6789Hi10", 1) → true true OK
prefixAgain("Hi12345Hi6789Hi10", 2) → true true OK
prefixAgain("Hi12345Hi6789Hi10", 3) → true true OK
prefixAgain("Hi12345Hi6789Hi10", 4) → false true X
prefixAgain("a", 1) → false true X
prefixAgain("aa", 1) → true true OK
prefixAgain("ab", 1) → false true X
other tests
X
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.