Given an integer N, the task is to find the probability that a number with a number of digits as N is a palindrome.
The number may have leading zeros.
Input: N = 5
Output: 1 / 100
Input: N = 6
Output: 1 / 1000
- As leading zeroes are allowed total number of N digit number is 10N.
- A number is a palindrome when first N/2 digits match with last N/2 digits in reverse order.
- For even number of digits, we can pick first N/2 digits and then duplicate them to form the rest of N/2 digits so we can choose (N)/2 digits.
- For an odd number of digits we can pick first (N-1)/2 digits and then duplicate them to form the rest of (N-1)/2 digits so we can choose (N+1)/2 digits.
- So the probability that an N digit number is palindrome is 10ceil( N / 2 ) / 10N or 1 / 10floor( N / 2 )
Below is the implementation of the approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- XOR and OR of all N-digit palindrome number
- Sum of all N digit palindrome numbers
- Count of N-digit Palindrome numbers
- Largest palindrome which is product of two N-digit numbers : Set 2
- Largest palindrome which is product of two n-digit numbers
- Min steps to convert N-digit prime number into another by replacing a digit in each step
- Count of Numbers in Range where first digit is equal to last digit of the number
- Find the remainder when First digit of a number is divided by its Last digit
- Last digit of a number raised to last digit of N factorial
- Largest number less than N with digit sum greater than the digit sum of N
- Probability such that two subset contains same number of elements
- Random number generator in arbitrary probability distribution fashion
- Probability of getting a perfect square when a random number is chosen in a given range
- Check if a number with even number of digits is palindrome or not
- Count of N-digit numbers having digit XOR as single digit
- Number of times a number can be replaced by the sum of its digits until it only contains one digit
- Queries on sum of odd number digit sums of all the factors of a number
- Check if a number is Palindrome
- Largest number less than N whose each digit is prime number
- Count the number of occurrences of a particular digit in a number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.