VOOZH about

URL: https://www.geeksforgeeks.org/dsa/largest-palindrome-product-two-n-digit-numbers/

⇱ Largest palindrome which is product of two n-digit numbers - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Largest palindrome which is product of two n-digit numbers

Last Updated : 22 Aug, 2022

Given a value n, find out the largest palindrome number which is product of two n digit numbers.

Examples : 

Input : n = 2
Output : 9009 
9009 is the largest number which is product of two 
2-digit numbers. 9009 = 91*99.

Input : n = 3
Output : 906609


Below are steps to find the required number. 

  1. Find a lower limit on n digit numbers. For example, for n = 2, lower_limit is 10.
  2. Find an upper limit on n digit numbers. For example, for n = 2, upper_limit is 99.
  3. Consider all pairs of numbers wherever number lies in range [lower_limit, upper_limit]

Below is the implementation of above steps. 

Output :

9009


Time Complexity: O(n*n*log10(product)), where n is the upper limit calculated and product is (product of two n-digit numbers)
Auxiliary Space: O(1), as no extra space is required|
The approach used in this post is simple and straightforward. Please comment if you find a better approach.
 

Comment
Article Tags:
Article Tags: