Super Palindromes - Problem
A super-palindrome is a positive integer that satisfies two conditions:
- It is a palindrome (reads the same forwards and backwards)
- It is the square of a palindrome
Given two positive integers left and right represented as strings, return the number of super-palindromes in the inclusive range [left, right].
Example: If we have a palindrome like 11, its square is 121, which is also a palindrome. Therefore, 121 is a super-palindrome.
Input & Output
Example 1 — Small Range
$
Input:
left = "1", right = "10"
›
Output:
2
💡 Note:
Super-palindromes in [1,10]: 4 (2² and both 4,2 are palindromes) and 9 (3² and both 9,3 are palindromes)
Example 2 — Larger Range
$
Input:
left = "1", right = "1000"
›
Output:
4
💡 Note:
Super-palindromes: 1 (1²), 4 (2²), 9 (3²), and 121 (11²). All are palindromes and squares of palindromes.
Example 3 — High Range
$
Input:
left = "100", right = "200"
›
Output:
1
💡 Note:
Only 121 (11²) is a super-palindrome in range [100,200]. 121 is palindrome and 11 is palindrome.
Constraints
- 1 ≤ int(left) ≤ int(right) ≤ 1018
- left and right consist of only digits
- left and right will not have leading zeros
Visualization
Tap to expand
Understanding the Visualization
1
Input
Range [left, right] to search for super-palindromes
2
Process
Find numbers that are palindromes AND squares of palindromes
3
Output
Count of super-palindromes in the range
Key Takeaway
🎯 Key Insight: Generate palindromes first, then check if their squares are also palindromes - much more efficient than checking every number!
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code