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

We'll say that a "mirror" section in an array is a group of contiguous elements such that somewhere in the array, the same group appears in reverse order. For example, the largest mirror section in {1, 2, 3, 8, 9, 3, 2, 1} is length 3 (the {1, 2, 3} part). Return the size of the largest mirror section found in the given array.

maxMirror([1, 2, 3, 8, 9, 3, 2, 1]) → 3
maxMirror([1, 2, 1, 4]) → 3
maxMirror([7, 1, 2, 9, 7, 2, 1]) → 2
gnanagowthaman sankarAsked:
Who is Participating?
but how 3 elements

There are not "3 elements". The question is asking you to return the *length* of the longest contiguous and contiguously mirrorable sequence of array elements.

The answer is 3 there, because it is arrived at from the length of 121, (which is 3 of course), and which happens to be a palindromic number (it's the same backwards), so that qualifies it as being there  more than once. It's a mirror of itself.
My way (which may not be the most efficient way), would be to mirror the array, loop and then take all lengths possible, and find if that piece is to be found in the mirrored length.

var found_length = 0
loop i=1 to mirror.length
   loop j=1 to (mirror.length - i)
      'take the contiguous j is starting point, i is length, match if it's found in mirror_array
           if found and andalso  j > found_length then found_length = j
gnanagowthaman sankarAuthor Commented:
maxMirror([1, 2, 1, 4]) → 3   How 3 elements here 121 or 214 or 412 is not in sequence but how 3 elements
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.