In an alien language, the order of the alphabet is different from the English alphabet. Given a string order representing the order of the alphabet in the alien language and a list of strings words, where each word is composed of the alien alphabet, determine if the words are sorted lexicographically according to the alien alphabet.
To solve this problem, you need to:
order.words based on the alien alphabet order.true if the words are sorted lexicographically according to the alien order, or false otherwise.Example 1:
Input: order = "za", words = ["z","zaa"] Output: true Explanation: The first word is "z" and the second word is "zaa". Since 'z' is the first character according to the order and "zaa" is the second word, the words are sorted lexicographically.
Example 2:
Input: order = "zb", words = ["z","zb"] Output: false Explanation: The first word is "z" and the second word is "zb". According to the order "zb", 'z' should be followed by 'b', so the words are not sorted lexicographically.
Example 3:
Input: order = "abc", words = ["abcd","abc"] Output: true Explanation: The first word is "abcd" and the second word is "abc". Since "abc" is a prefix of "abcd", the words are sorted lexicographically.
1 <= words.length <= 1001 <= words[i].length <= 100order.length == 26order consists of all lowercase English letters.words[i] are in order.words[i] consists of only lowercase English letters.order string.