troubleshooting Question

prefixAgain java challenge

Avatar of gudii9
gudii9Flag for United States of America asked on
Java EEJavaProgramming Languages-OtherProgramming
16 Comments3 Solutions205 ViewsLast Modified:
Hi,
I am working on below challenge
http://codingbat.com/prob/p136417
I tried my code as below
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 result
Expected      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         

how to  improve my approach, results and design of this challenge. How do i make a graphical venn or flow chart or some other relevant diagram to design it before writing code to decide best strategy?
 Please advise
ASKER CERTIFIED SOLUTION
krakatoa

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 16 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 16 Comments.
Try for 7 days

”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.

-Mike Kapnisakis, Warner Bros