First Digit Equals Last — Solution & Editorial
Group by digit length: for length < the bound's length, count freely (first digit 1-9, last equals it, middle arbitrary); for the bound's length, enumerate the constrained prefix. (A full digit DP carrying the first digit handles 1018.)
Complexity: O(range of digit lengths)