...

/

Verifying an Alien Dictionary

Verifying an Alien Dictionary

Try to solve the Verifying an Alien Dictionary problem.

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 the same), then the shorter word is considered smaller.

Constraints:

  • 11 \leq words.length 103\leq 10^3
  • 11 \leq words[i].length 20\leq 20
  • order.length ==26== 26
  • All the characters in words[i] and order are lowercase English letters.

Examples

Understand the problem

Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:

Verifying an Alien Dictionary

1

What is the output if the following list of words and order are given as input?

words = [“wrt”, “wrf”, “er”, “ett”, “rftt”]

order = “hlabcdgiwjkmnopqerstfuvxyz”

A)

TRUE

B)

FALSE

Question 1 of 40 attempted

Figure it out!

We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.

Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence.

1
2
3
4
5
6

Try it yourself

Implement your solution in the following coding playground:

Press + to interact
Python
usercode > main.py
def verify_alien_dictionary(words, order):
# Replace this placeholder return statement with your code
return False
Verifying an Alien Dictionary

Access this course and 1200+ top-rated courses and projects.