Back to course home
0% completed
Vote For New Content
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>
num
consists of digits.
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page
Problem Statement
Examples
Try it yourself