Search⌘ K
AI Features

Verifying an Alien Dictionary

Understand how to verify if words follow a specified alien dictionary order by applying lexicographical comparison rules. Explore the use of topological sort to assess character ordering and master checking if a given list of words is sorted according to an alien alphabet permutation.

Statement

In an alien language, the alphabet consists of the same lowercase English letters but arranged in a different order.

Given a list of words, words, written in this alien language, and a string order representing the order of the alien alphabet (as a permutation of lowercase letters), return TRUE if the words are sorted lexicographically according to order; otherwise, return FALSE.

Note: A word a is considered lexicographically smaller than word b if:

  • At the first position where the two words differ, the character in a comes before the character in b in the given order string.

  • If one word is a prefix of the other (and all compared characters are ...