bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 866. Prime Palindrome

866. Prime Palindrome

Leetcode Solutions

Iterate Palindromes

  1. If n is less than or equal to 2, return 2 as it is the smallest prime number.
  2. If n is 11 or less, check the numbers 3, 5, 7, and 11 and return the smallest prime palindrome greater than or equal to n.
  3. For other values of n, find the palindromic root by taking the first half of the digits of n.
  4. Generate the next palindrome by incrementing the palindromic root and mirroring it to form the full palindrome.
  5. Check if the generated palindrome is prime. If it is, return it.
  6. If not, repeat steps 4 and 5 until a prime palindrome is found.
UML Thumbnail

Brute Force with Mathematical Shortcut

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...