Problem Statement
You are organizing a public event. Currently you are in the process of choosing its name. After some brainstorming, you've selected a list of words that would sound good as a part of the name. These words are given in String[] words.
You've decided that the name of your event must be a concatenation of two strings A and B where both A and B belong to the given list of words and the length of B is twice the length of A. Return the longest possible event name. If it is not possible to choose an event name that satisfies the given rules, return an empty String instead.
You've decided that the name of your event must be a concatenation of two strings A and B where both A and B belong to the given list of words and the length of B is twice the length of A. Return the longest possible event name. If it is not possible to choose an event name that satisfies the given rules, return an empty String instead.
Definition
- Class:
- EventName
- Method:
- findBest
- Parameters:
- String[]
- Returns:
- String
- Method signature:
- String findBest(String[] words)
- (be sure your method is public)
Notes
- The constraints guarantee that there is either no valid event name, or exactly one longest possible event name.
Constraints
- words will contain between 2 and 50 elements, inclusive.
- Each element of words will contain between 1 and 50 characters, inclusive.
- The first character in each element of words will be an uppercase letter ('A'-'Z'). Each other character will be a lowercase letter ('a'-'z').
- No two elements of words will have the same length.
Examples
{"Tech", "Hi", "Olympics"}Returns: "TechOlympics"
Two names are possible here: "HiTech" and "TechOlympics". The second one is longer.{"Topcoder", "Tournament", "Coding", "Programming", "Problem"}Returns: ""
No valid name can be created from these words.{"Jig", "Wrie", "Lazzaroni", "Paduasoy", "Torvous", "Revict", "Libelluloid"}Returns: "WriePaduasoy"
{"Stylomaxillary", "Mahican", "Turkey", "Perpetration", "Xanthorhiza", "Analyser", "Biped"}Returns: "MahicanStylomaxillary"
{"Def", "A", "Bc"}Returns: "ABc"