Question: You are given a string S , which consists entirely of decimal digits ( 0 - 9 ) . Using digits from S , create

You are given a string S, which consists entirely of decimal digits (0-9). Using digits from S, create a palindromic number with the largest possible decimal value. You should use at least one digit and you can reorder the digits. A palindromic number remains the same when its digits are reversed; for instance, "7","44" or "83238". Any palindromic number you create should not, however, have any leading zeros, such as in "0990" or "010".
For example, decimal palindromic numbers that can be created from "8199" are: "1","8","9","99","919" and "989". Among them, "989" has the largest value.
Write a function:
class Solution public String
solution(String S):)
that, given a string S of N digits, returns the string representing the palindromic number with the largest value.
Examples:
1. Given "39878", your function should return "898".

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!