Connection Status:
Competition Arena > PalindromeMaker
SRM 274 · 2005-11-23 · by Andrew_Lazarev · Brute Force, Sorting
Class Name: PalindromeMaker
Return Type: String
Method Name: make
Arg Types: (string)
Problem Statement

Problem Statement

A palindrome is a string that is spelled the same forward and backward. We want to rearrange letters of the given string baseString so that it becomes a palindrome.

You will be given a String baseString. Return the palindrome that can be made from baseString. When more than one palindrome can be made, return the lexicographically earliest (i.e., the one that occurs first in alphabetical order). Return "" (the empty string) if no palindromes can be made from baseString.

Constraints

  • baseString will contain between 1 and 50 characters, inclusive.
  • Each character in baseString will be an uppercase letter ('A'-'Z').
Examples
0)
"AABB"
Returns: "ABBA"
1)
"AAABB"
Returns: "ABABA"
2)
"ABACABA"
Returns: "AABCBAA"
3)
"ABCD"
Returns: ""
4)
"ZYXWVUTSRQPONMLKJIHGFEDCBA"
Returns: ""

Submissions are judged against all 104 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class PalindromeMaker with a public method string make(string baseString) · 104 test cases · 2 s / 256 MB per case

Submitting as anonymous