Count Palindrome Numbers in Range M to N

E · easyP · Verified PYQstrings

Given two integers M and N (M <= N), count how many numbers in the range [M, N] (inclusive) are palindromes. A palindrome number reads the same forwards and backwards. Example: 11, 121, 131, 9 are palindromes.

M <= N, both non-negative integers
Input
10
20
Output
1
For each number i from M to N: convert to string, check if str(i)==str(i)[::-1]. Count matches.
Only 11 is a palindrome between 10 and 20.
← Count Number of DigitsCount Subsets with Given Sum →
Report an issue with this question