Designing a Custom Alphabet
You are given an array of strings names containing only lowercase English letters. These names are supposedly sorted lexicographically according to a newly invented, unknown permutation of the 26-letter English alphabet.
Return a string representing the valid 26-letter alphabet ordering. If multiple valid permutations exist, return the lexicographically smallest one. If no valid ordering exists (for example, if there is a cycle or an invalid prefix condition), return "".
Example 1:
Input: names = ["z", "x"]
Output: "abcdefghijklmnopqrstuvwyzx"
Explanation:
We know 'z' < 'x'. The rest of the letters default to their alphabetical order at the front.
Example 2:
Input: names = ["z", "y", "x"]
Output: "abcdefghijklmnopqrstuvwzyx"
Explanation:
We have 'z' < 'y' and 'y'< 'x', so just make the order of zyx indexes in increasing order.
Now Your Turn!
Pick the correct output for the given inputInput: names = ["abc", "ab"]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= names.length <= 100
- 1 <= names[i].length <= 100
- All strings are unique and contain only lowercase English letters.