In this Leetcode Palindromic Numbers problem solution we have given A and B, count the numbers N such that A ≤ N ≤ B, and N is a palindrome.


HackerEarth Palindromic Numbers problem solution


HackerEarth Palindromic Numbers problem solution.

def check(s):
    q=s[::-1]
    if s==q: return True
    return False
t=input()
for i in range(t):
    ans=0
    x=raw_input()
    a=int(x.split()[0])
    b=int(x.split()[1])
    for j in range(a,b+1):
  if check(str(j)):
      ans += 1
    print ans


Second solution

#include <iostream>
using namespace std;

int ispallin(int n){
    int arr[10],count = 0;
  while(n!=0){
    arr[count++] = n%10;
    n/=10;
  }
  int i=0,j=count-1;
  while(i<j){
    if(arr[i]!=arr[j]) return 0;
    i++; j--;
  }
  return 1;
}

int main()
{
    int t;
    cin >> t;
    while(t--){
      int a,b;
      cin >>  a >> b;
      int ans = 0,count=0;;
      for(int i=a;i<=b;i++) if(ispallin(i)) count++;
      cout << count << endl;
    }
    return 0;
}