mediumCountingGreedyHash TableString 0 views

Largest Palindromic Number

You are given a string num consisting of digits only.

You are given a string num consisting of digits only.

Return the largest palindromic integer (in the form of a string) that can be formed using digits taken from num. It should not contain leading zeroes.

Notes:

Largest Palindromic Number diagram

Example 1

Input: num = "444947137"

Output: "7449447"

Explanation: Use the digits "4449477" from "444947137" to form the palindromic integer "7449447". It can be shown that "7449447" is the largest palindromic integer that can be formed.

Example 2

Input: num = "00009"

Output: "9"

Explanation: It can be shown that "9" is the largest palindromic integer that can be formed. Note that the integer returned should not contain leading zeroes.

Constraints

  • 1 <= num.length <= 10^5
  • num consists of digits.

Hints

Companies

No companies reported yet.

Discussion

Sign in to join the discussion.

Loading discussion...

Test results

No test cases yet.