4 kyu

Palindrome Counter

25 of 69M1Miketro

Description:

Background

Palindromes are a special type of number (in this case a non-negative integer) that reads the same backwards as forwards. A number defined this way is called palindromic.

  • The following numbers are palindromes: 0, 252, 769967, 1111111.

  • The following numbers are not palindromes: 123, 689, 565656, 12345432.

Problem Description

In this kata, you are required to build a function that receives two arguments, a and b, and returns the number of integer palindromes between a and b inclusive.

Examples

  • If a is 6 and b is 11, the function should output 5 because there are 5 palindromes between 6 and 11 inclusive: 6, 7, 8, 9 and 11.

  • If a is 150 and b is 250, the function should output 10 because there are 10 palindromes between 150 and 250 inclusive: 151, 161, 171, 181, 191, 202, 212, 222, 232 and 242.

  • If a is 1002 and b is 1110, the function should output 0: there are no palindromes between 1002 and 1110 inclusive.

Input Constraints

  • Fixed test cases: 0 ≤ a, b100 (one hundred)

  • Small test cases: 0a, b10^5 (one hundred thousand)

  • Medium test cases: 0a, b10^10 (ten billion)

  • Large test cases: 0a, b10^15 (one quadrillion)

Ideally, a program should pass all the test cases in no more than 800 milliseconds.

Edge Cases

  • Note that 0 is palindromic.

  • Numbers starting with the digit 0 do not count, with the exception of 0 itself.

This is my first kata created. Hope you enjoy! <3

Number Theory
Mathematics
Performance

More By Author:

Check out these other kata created by M1Miketro

Stats:

CreatedMay 14, 2023
PublishedMay 14, 2023
Warriors Trained929
Total Skips30
Total Code Submissions2157
Total Times Completed69
JavaScript Completions25
Python Completions52
Total Stars54
% of votes with a positive feedback rating90% of 21
Total "Very Satisfied" Votes18
Total "Somewhat Satisfied" Votes2
Total "Not Satisfied" Votes1
Total Rank Assessments8
Average Assessed Rank
4 kyu
Highest Assessed Rank
3 kyu
Lowest Assessed Rank
5 kyu
Ad
Contributors
  • M1Miketro Avatar
  • dfhwze Avatar
Ad