Can Anyone help me. Please explain the question i cant get it and logic behind it.

String ( 2 loop based problem)

Given a string, look for a mirror image (backwards) string at both the beginning and end of the given string. In other words, zero or more characters at the very begining of the given string, and at the very end of the string in reverse order (possibly overlapping). For example, the string "abXYZba" has the mirror end "ab".

mirrorEnds("abXYZba") → "ab"
mirrorEnds("abca") → "a"
mirrorEnds("aba") → "aba"
gnanagowthaman sankarAsked:
Who is Participating?
 
Rgonzo1971Commented:
HI,

if you begin from the start of the string and the end of the string what are the same characters
mirrorEnds("abXYZba") "abXYZba" → "abXYZba" → "ab"
mirrorEnds("abca") "abca" → "a"
mirrorEnds("aba") → "aba"→ "aba"→ "aba"→ "aba"
bold from the start italic from the end

Regards
0
 
rrzCommented:
The word "mirror" is confusing. If you used an actual mirror, you would not be able to read the characters. I think the word "backwards" is a better description.  If the first character equals the last character, then add it to the result. If the second character from the beginning equals the second character from the end, then add that to the result.  You can continue doing that comparison until you find a mismatch.  You could write the code just like that.
0
 
Shaun VermaakTechnical Specialist/DeveloperCommented:
You need to do two loops, one from the first character to last and one from last to first.
Do this and build string until the character in the two loops do not match anymore
0
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
You would definitely NOT need two loops. You only need one loop, and at each iteration of that one loop you check two characters, but it is still only one loop.
0
 
Shaun VermaakTechnical Specialist/DeveloperCommented:
I am only saying that in the context "2 loop based problem"
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.