We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def is_palindrome(n):
return str(n) == str(n)[::-1]
def checker(k):
for i in range(999, 99, -1):
if k % i == 0 and 100 <= k // i <= 999:
return True
return False
def main():
t = int(input())
for _ in range(t):
n = int(input())
for i in range(n - 1, 101101 - 1, -1):
if is_palindrome(i) and checker(i):
print(i)
break
if name == "main":
main()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Project Euler #4: Largest palindrome product
You are viewing a single comment's thread. Return to all comments →
def is_palindrome(n): return str(n) == str(n)[::-1] def checker(k): for i in range(999, 99, -1):
if k % i == 0 and 100 <= k // i <= 999: return True return False
def main(): t = int(input()) for _ in range(t): n = int(input()) for i in range(n - 1, 101101 - 1, -1): if is_palindrome(i) and checker(i): print(i) break
if name == "main": main()