π― Super Palindromes Problem
A super-palindrome is a fascinating mathematical concept - it's a number that is both a palindrome and the square of another palindrome!
Given two positive integers left and right represented as strings, your task is to count how many super-palindromes exist in the inclusive range [left, right].
What makes a super-palindrome?
- The number must be a palindrome (reads the same forwards and backwards)
- It must be the perfect square of another palindrome
Example: The number 9 is a super-palindrome because:
9is a palindrome β9 = 3Β²and3is also a palindrome β
Your goal is to efficiently count all such numbers in the given range without checking every possible number!
Input & Output
Visualization
Time & Space Complexity
We generate palindromes up to β(right), and for each palindrome we perform string operations taking O(L) time where L is the number of digits
Space for storing string representations of numbers, where L is the maximum number of digits
Constraints
- 1 β€ left β€ right β€ 1018
- left and right are represented as strings
- The range can be extremely large, making brute force impractical
- Super-palindromes are relatively rare, especially for large numbers