Practice/Google/Leetcode 269. Alien Dictionary
CodingMust
You are given a list of words from an ancient alien language that uses characters similar to English but with a completely different alphabetical ordering. The words are sorted lexicographically according to the alien language's character ordering rules.
Your task is to determine the order of characters in this alien alphabet. If multiple valid orderings exist, return any one of them. If no valid ordering exists (due to contradictions or invalid input), return an empty string.
Example 1:
` Input: words = ["wrt", "wrf", "er", "ett", "rftt"] Output: "wertf" Explanation:
Example 2:
Input: words = ["z", "x"] Output: "zx" Explanation: From the ordering, z must come before x in the alien alphabet.
Example 3:
Input: words = ["abc", "bca", "cab"] Output: "" Explanation: This input creates a cycle (a<b, b<c, c<a), so no valid ordering exists.
Example 4:
Input: words = ["monster", "mon"] Output: "" Explanation: Invalid because "mon" is a prefix of "monster" but appears after it, violating lexicographic ordering.