#K78747. Alien Dictionary Sorted Order
Alien Dictionary Sorted Order
Alien Dictionary Sorted Order
You are given a list of words written in an alien language and a string that represents the order of the alien alphabet. Your task is to determine whether the words are sorted lexicographically according to this alien language.
The order of the alphabet is given as a permutation of the lowercase English letters. You need to check the list of words and decide if they are in non-decreasing order according to the given alphabet.
For example, given the words hello
and leetcode
with the order hlabcdefgijkmnopqrstuvwxyz
, the output is True
.
inputFormat
The input is read from standard input (stdin). The first line contains an integer T, representing the number of test cases. For each test case, the input consists of three parts:
- An integer n representing the number of words.
- A single line containing n space-separated words.
- A string representing the order of the alien alphabet.
For each test case, you need to determine if the words are sorted according to the given alien order.
outputFormat
For each test case, output a single line with either True or False, indicating whether the list of words is sorted according to the alien dictionary order.## sample
4
2
hello leetcode
hlabcdefgijkmnopqrstuvwxyz
3
word world row
worldabcefghijkmnpqstuvxyz
1
apple
abcdefghijklmnopqrstuvwxyz
3
app apple ap
abcdefghijklmnopqrstuvwxyz
True
False
True
False
</p>