Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Which company reprensents the best investment opportunity and why?

Answered: 1 week ago