+ 1

I need help with the python program

Given a Integer array A[] of n elements Your task is to complete the function Palindrome Array. Which will return 1 if all the elements of the Array are palindrome otherwise it will return 0. Code: https://code.sololearn.com/caTa1ZM1QsV0 i want to solve this program using "Two pointer algorithm" approach. Can anyone suggest where i am going wrong? Note: please do not suggest any reverse in built function or brute force approach

1st Jan 2022, 1:07 PM
Edwin
Edwin - avatar
3 Antworten
+ 2
Is this what you expected? You were trying to access arr[i][end] where len (arr [i]) = 3 and end = n-1 where n = 5 https://code.sololearn.com/co75rbIpZDs7/?ref=app
1st Jan 2022, 2:15 PM
CGM
CGM - avatar
+ 2
@Cristian Gabriel Mazzulla Thank you i got it now remove line 16 and 17 it was for debugging purpose haha
1st Jan 2022, 2:50 PM
Edwin
Edwin - avatar
+ 2
updated code: def PalindromeArray(arr, n): isPalindrome=1 for i in range(n): start=0 end=len(arr[i])-1 if start < end: if arr[i][start] == arr[i][end]: start+=1 end-=1 elif(start>end or start == end): isPalindrome=0 return isPalindrome return isPalindrome
1st Jan 2022, 2:51 PM
Edwin
Edwin - avatar