DIY: Verifying an Alien Dictionary

Solve the interview question "Verifying an Alien Dictionary" in this lesson.

Problem statement

In this coding exercise, you are given a list of words written in an alien language. Surprisingly, the aliens also use lowercase English letters, but possibly in a different order. The order of the alphabet is some permutation of lowercase letters of the English language.

Given an array of words written in the alien language and the order of the alphabet, return true if and only if the given words are sorted lexicographically in this alien language.


You can assume the following constraints:

  • 1 <= words.length <= 100
  • 1 <= words[i].length <= 20
  • order.length == 26
  • All the characters in words[i] and order are lowercase English letters.


The input will contain an array of strings, words, and a string, order. Here are two example inputs to the function:

// Sample Input 1
words = ["hello", "world"]
order = "hwabcdefgijklmnopqrstuvxyz"

// Sample Input 2
words = ["educated", "educate"]
order = "educatebfghijklmnopqrsvwxyz"


For the input given above, the output will be:

// Sample Output 1

// Sample Output 2

Coding exercise

For this coding exercise, you have to implement the verifyAlienDictionary(words, order) function, wherein words represents an array of words and the order represents the order of the alphabets. The function will return true or false depending on whether the given array of words belongs to the alien language or not.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.