Count of N-digit Palindrome numbers Last Updated : 10 Mar, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report Given an integer N, the task is to find the count of N-digit Palindrome numbers.Examples: Input: N = 1 Output: 9 {1, 2, 3, 4, 5, 6, 7, 8, 9} are all the possible single digit palindrome numbers.Input: N = 2 Output: 9 Approach: The first digit can be any of the 9 digits (not 0) and the last digit will have to be same as the first in order for it to be palindrome, the second and the second last digit can be any of the 10 digits and same goes for the rest of the digits. So, for any value of N, the count of N-digit palindromes will be 9 * 10(N - 1) / 2.Below is the implementation of the above approach: C++ // C++ implementation of the approach #include <bits/stdc++.h> using namespace std; // Function to return the count // of N-digit palindrome numbers int nDigitPalindromes(int n) { return (9 * pow(10, (n - 1) / 2)); } // Driver code int main() { int n = 2; cout << nDigitPalindromes(n); return 0; } Java // Java implementation of the approach class GFG { // Function to return the count // of N-digit palindrome numbers static int nDigitPalindromes(int n) { return (9 * (int)Math.pow(10, (n - 1) / 2)); } // Driver code public static void main(String []args) { int n = 2; System.out.println(nDigitPalindromes(n)); } } // This code is contributed by Code_Mech Python3 # Python3 implementation of the approach # Function to return the count # of N-digit palindrome numbers def nDigitPalindromes(n) : return (9 * pow(10, (n - 1) // 2)); # Driver code if __name__ == "__main__" : n = 2; print(nDigitPalindromes(n)); # This code is contributed by AnkitRai01 C# // C# implementation of the approach using System; class GFG { // Function to return the count // of N-digit palindrome numbers static int nDigitPalindromes(int n) { return (9 * (int)Math.Pow(10, (n - 1) / 2)); } // Driver code public static void Main(String []args) { int n = 2; Console.WriteLine(nDigitPalindromes(n)); } } // This code is contributed by Rajput-Ji JavaScript <script> // Javascript implementation of the approach // Function to return the count // of N-digit palindrome numbers function nDigitPalindromes(n) { return (9 * Math.pow(10, parseInt((n - 1) / 2))); } // Driver code var n = 2; document.write(nDigitPalindromes(n)); </script> Output: 9 Time Complexity: O(log n) Auxiliary Space: O(1) Comment More infoAdvertise with us Next Article Count of N-digit Palindrome numbers S spp____ Follow Improve Article Tags : Mathematical DSA palindrome Practice Tags : Mathematicalpalindrome Similar Reads Sum of all N digit palindrome numbers Given a number N. The task is to find the sum of all N-digit palindromes. Examples: Input: N = 2 Output: 495 Explanation: 11 + 22 + 33 + 44 + 55 + 66 + 77 + 88 + 99 = 495 Input: N = 7 Output: 49500000000 Naive Approach:Run a loop from 10^(n-1) to 10^(n) - 1 and check when the current number is palin 7 min read Count of N digit palindromic numbers divisible by 9 Given an integer N, the task is to count the number of N digit palindromic numbers containing digits from 1 to 9 and divisible by 9. Examples: Input: N = 1 Output: 1 Explanation: Only 9 is 1 digit number which is palindrome and divisible by 9.Input: N = 3 Output: 9 Explanation: Three digit numbers t 4 min read Find all palindrome numbers of given digits Given an integer D, the task is to find all the D-digit palindrome numbers.Examples: Input: D = 1 Output: 1 2 3 4 5 6 7 8 9Input: D = 2 Output: 11 22 33 44 55 66 77 88 99 Approach: Numbers with D-digits start from 10(D - 1) to 10D - 1. So, start checking every number from this interval whether it is 5 min read Count the number of digits of palindrome numbers in an array Given an array arr[] with N integers. The task is to count all the digits of all palindrome numbers present in the array.Examples: Input: arr[] = {121, 56, 434} Output: 6 Only 121 and 434 are palindromes and digitCount(121) + digitCount(434) = 3 + 3 = 6Input: arr[] = {56, 455, 546, 234} Output: 0 Ap 8 min read N'th palindrome of K digits Given two integers n and k, Find the lexicographical nth palindrome of k digits.Examples: Input : n = 5, k = 4 Output : 1441 Explanation: 4 digit lexicographical palindromes are: 1001, 1111, 1221, 1331, 1441 5th palindrome = 1441 Input : n = 4, k = 6 Output : 103301 Naive Approach A brute force is t 13 min read Like