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:
- 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
- Largest palindrome which is product of two N-digit numbers : Set 2
- 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
- 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
- Probability of getting a perfect square when a random number is chosen in a given range
- Random number generator in arbitrary probability distribution fashion
- Check if a number with even number of digits is palindrome or not
- Queries on sum of odd number digit sums of all the factors of a number
- Number of times a number can be replaced by the sum of its digits until it only contains one digit
- Check if a number is Palindrome