Count Palindrome Numbers in Range M to N
E · easyP · Verified PYQstrings
Problem
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.
Constraints
M <= N, both non-negative integers
Example
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.