Verifying an Alien Dictionary

Easy

Description

Given a sequence of words in an alien language sorted lexicographically by their rules, return true if words are sorted in that alien dictionary order.

Examples

Input:words = ["hello","leetcode"], order = "hlabcdefgijkmnopqrstuvwxyz"
Output:true
Explanation:

h < l in alien order.

Input:words = ["word","world","row"], order = "worldabcefghijkmnpqstuvxyz"
Output:false
Explanation:

In the alien alphabet, 'd' comes after 'l', so "word" > "world". The words are not in sorted order.

Input:words = ["apple","app"], order = "abcdefghijklmnopqrstuvwxyz"
Output:false
Explanation:

Although 'app' is a prefix of 'apple', in lexicographical order the shorter word should come first. Since 'apple' appears before 'app' in the input, the words are not properly sorted.

Constraints

  • 1 ≤ words.length ≤ 100

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!