Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a python code and try to explain the thought process/ procedure. Thank you

ID: 3595530 • Letter: W

Question

Write a python code and try to explain the thought process/ procedure. Thank you!

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

Explanation / Answer

def maxMirror(nums):
length = len(nums)
total = 0
highest = 0
for x in range(length):
total = 0
j = length - 1
while(x + total < length and j > -1):
if nums[x + total] == nums[j]:
total += 1;
elif total > 0:
highest =max(total, highest)
total = 0
j = j - 1
highest = max(total, highest);
return highest

print(maxMirror([1, 2, 3, 8, 9, 3, 2, 1]))
print(maxMirror([1, 2, 1, 4]))
print(maxMirror([7, 1, 2, 9, 7, 2, 1]))

# copy pastable code link: https://paste.ee/p/kwWJI

Sample output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote