Alien Word Order
In a normal dictionary, letters follow a through z, but an alien language may use a different alphabet order. Given a list of words words and a string order describing that alphabet, check whether the words are sorted lexicographically by the alien rules. Return True if they are in order, otherwise return False.
Примеры
Ввод
["hello", "leetcode"], "hlabcdefgijkmnopqrstuvwxyz"Вывод
TrueВвод
["word", "world", "row"], "worldabcefghijkmnpqstuvxyz"Вывод
FalseВвод
["apple", "app"], "abcdefghijklmnopqrstuvwxyz"Вывод
FalseНужно реализовать
def is_alien_sorted(words: list[str], order: str) -> bool:
Теги
stringshashmapsorting
Prijavi se da vidiš povijest predaja
PrijavaPrijavi se da koristiš AI mentora
PrijavaVisible tests
1
Input
["hello","leetcode"], "hlabcdefgijkmnopqrstuvwxyz"Expected
True2
Input
["word","world","row"], "worldabcefghijkmnpqstuvxyz"Expected
False3
Input
["apple","app"], "abcdefghijklmnopqrstuvwxyz"Expected
False4
Input
["a","b","c"], "abcdefghijklmnopqrstuvwxyz"Expected
True5
Input
["kuvp","q"], "ngxlkthsjuoqcpavbfdermiywz"Expected
True6
Input
["row","word","world"], "worldabcefghijkmnpqstuvxyz"Expected
FalseFocus radio
Paused · SomaFM · Fluid