
Largest Palindromic Number (medium)
Problem Statement
Given a string s containing 0 to 9 digits, create the largest possible palindromic number using the string characters. It should not contain leading zeroes.
A palindromic number reads the same backward as forward.
If it's not possible to form such a number using all digits of the given string, you can skip some of them.
Examples
Example 1
- Input: s = "323211444"
- Expected Output: "432141234"
- Justification: This is the largest palindromic number that can be formed from the given digits.
Example 2
- Input: s = "998877"
- Expected Output: "987789"
- Justification: "987789" is the largest palindrome that can be formed.
Example 3
- Input: s = "54321"
- Expected Output: "5"
- Justification: Only "5" can form a valid palindromic number as other digits cannot be paired.
Constraints:
- 1 <= num.length <= 10<sup>5</sup>
numconsists of digits.
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory