troubleshooting Question

xyzMiddle java challenge

Avatar of gudii9
gudii9Flag for United States of America asked on
Java EEJavaProgrammingProgramming Languages-OtherJava App Servers
33 Comments1 Solution576 ViewsLast Modified:
I am working on below challenge
I tried my code as below
public boolean xyzMiddle(String str) {
 int len = str.length();
 int lenMid = len / 2;
 int lenMidAssumeMax = lenMid + 1;
 int lenMidAssumeMin = lenMid - 1;
 int yPos = str.indexOf('y');
 if (yPos == lenMid || yPos == lenMidAssumeMax || yPos == lenMidAssumeMin) {
  return true;

 return false;

I am getting below result
Expected      Run            
xyzMiddle("AAxyzBB") → true      true      OK         
xyzMiddle("AxyzBB") → true      true      OK         
xyzMiddle("AxyzBBB") → false      true      X         
xyzMiddle("AxyzBBBB") → false      false      OK         
xyzMiddle("AAAxyzB") → false      true      X         
xyzMiddle("AAAxyzBB") → true      true      OK         
xyzMiddle("AAAAxyzBB") → false      true      X         
xyzMiddle("AAAAAxyzBBB") → false      true      X         
xyzMiddle("1x345xyz12x4") → true      true      OK         
xyzMiddle("xyzAxyzBBB") → true      false      X         
xyzMiddle("xyzAxyzBxyz") → true      false      X         
xyzMiddle("xyzxyzAxyzBxyzxyz") → true      false      X         
xyzMiddle("xyzxyzxyzBxyzxyz") → true      false      X         
xyzMiddle("xyzxyzAxyzxyzxyz") → true      false      X         
xyzMiddle("xyzxyzAxyzxyzxy") → false      false      OK         
xyzMiddle("AxyzxyzBB") → false      false      OK         
xyzMiddle("") → false      true      X         
xyzMiddle("x") → false      true      X         
xyzMiddle("xy") → false      true      X         
xyzMiddle("xyz") → true      true      OK         
xyzMiddle("xyzz") → true      true      OK         
other tests

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
Join our community to see this answer!
Unlock 1 Answer and 33 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 1 Answer and 33 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