Longest Palindrome in an Array

    0

    0

    CrypticSai-08

    def isPalindrome(n):
       divisor = 1
       while (int(n / divisor) >= 10):
          divisor *= 10
       while (n != 0):
          leading = int(n / divisor)
          trailing = n % 10
          if (leading != trailing):
            return False
          n = int((n % divisor) / 10)
          divisor = int(divisor / 100)
       return True
    # Function to find the largest palindromic element
    def largestPalindrome(arr, n):
       currentMax = -1
       for i in range(0, n, 1):
          if (arr[i] > currentMax and isPalindrome(arr[i])):
             currentMax = arr[i]
       return currentMax
    # Driver Code
    arr = [1, 232, 5545455, 909090, 161]
    n = len(arr)
    # print required answer
    print(largestPalindrome(arr, n))
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.