
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
In order to form a valid palindrome, other than the middle digit in an odd-length palindrome, every digit needs to exist on both sides.
A longer palindrome implies a larger valued palindrome. For palindromes of the same length, the larger digits should occur first.
We can count the occurrences of each digit and build the palindrome starting from the ends. Starting from the larger digits, if there are still at least 2 occurrences of a digit, we can place these digits on each side.
Make sure to consider the special case for the center digit (if any) and zeroes. There should not be leading zeroes.