AlphabetOrderDiv2
SRM 705 Sponsored By Blizzard · 2016-12-22 · by ltaravilse
Problem Statement
One particular custom in Nlogonia was that in a good word the letters appear in non-decreasing order. For example, in English the word "ciel" is not a good word because in the alphabet 'i' is after 'e'. The word "ceil" is a good word because 'c' <= 'e' <= 'i' <= 'l'.
You are given the
In other words, return "Possible" if and only if there is at least one possible Nlogonian alphabet such that the letters of each word in words are in non-decreasing alphabetical order.
Constraints
- words has between 2 and 100 elements inclusive.
- The size of each element of words will be between 1 and 100 inclusive.
- Elements of words contains only English lowercase letters from 'a' to 'z'.
{"single","round","match"}
Returns: "Possible"
One possible Nlogonian alphabet is "bfjkmapqrositchundglevwxyz".
{"topcoder","topcoder"}
Returns: "Impossible"
The word "topcoder" can never be a good word. The character 'o' cannot be both before 'p' and after 'p' in the alphabet.
{"algorithm", "contest"}
Returns: "Impossible"
{"pink","floyd"}
Returns: "Possible"
{"gimnasia","y","esgrima","la","plata"}
Returns: "Impossible"
{"hello","hello"}
Returns: "Possible"
This is a good word for any alphabet in which the letters 'h', 'e', 'l', and 'o' appear in this order.
{"abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}
Returns: "Possible"
In this case the English alphabet is one of the valid permutations.
{"abc","bca"}
Returns: "Impossible"
'a' must come before 'c' (because of the first name) and after 'c' (because of the second name) and that is a contradiction. Thus, there is no valid solution.
{"aaaaa","eeeee","iiiii","ooooo","uuuuu"}
Returns: "Possible"
Any order is valid in this case
Submissions are judged against all 78 archived test cases, of which 9 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class AlphabetOrderDiv2 with a public method string isOrdered(vector<string> words) · 78 test cases · 2 s / 256 MB per case