ACL3 - Editorial

DIFFICULTY:

Beginner

PROBLEM:

A Palindromic number is a number that remains the same when its digits are reversed. You need to find count of Palindromic numbers between a range of two numbers (n1 & n2,such that n1 <= n2).

QUICK EXPLANATION:

Initialize a count variable with 0. Iterate each numbers between n1 and n2, starting with n1.If a number is Palindromic number increment count by 1.The final value of count is the answer.

EXPLANATION:

A number is Palindromic if it is remains same when it is reversed. For example 101,23432 are Palindromic numbers because when we reversed their digits we get a number itself, while numbers such as 12, 2345 & 100 are not Palindromic numbers.

  1. Initialize count = 0.
  2. Iterate each numbers one by one between n1 & n2 and apply step3 to each.
  3. If a number is Palindromic increment count by 1.
  4. Output the count as final result.

For Example:

Let n1 = 9 and n2 = 12

1. count = 0
2. Iterate Over numbers [9,10,11,12] one by one
3. 1st iteration (for 9) :Since 9 is a Palindromic number so count is incremented by 1.
   2nd iteration (for 10):10 is not a Palindromic number so count remains same.
   3rd iteration (for 11):11 is a Palindromic number so now count becomes 2.
   4th iteration (for 12):12 is not a Palindromic number so count remains 2.
4. Output 2.

TIME COMPLEXITY:

O(n2 – n1)