In an alien language, surprisingly, they also use English lowercase letters, but possibly in a different order. The order of the alphabet is some permutation of lowercase letters.

Given a sequence 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.

&nbsp;
Example 1:

Input: words = ["hello","leetcode"], order = "hlabcdefgijkmnopqrstuvwxyz"
Output: true
Explanation: As 'h' comes before 'l' in this language, then the sequence is sorted.


Example 2:

Input: words = ["word","world","row"], order = "worldabcefghijkmnpqstuvxyz"
Output: false
Explanation: As 'd' comes after 'l' in this language, then words[0] &gt; words[1], hence the sequence is unsorted.


Example 3:

Input: words = ["apple","app"], order = "abcdefghijklmnopqrstuvwxyz"
Output: false
Explanation: The first three characters "app" match, and the second string is shorter (in size.) According to lexicographical rules "apple" &gt; "app", because 'l' &gt; '∅', where '∅' is defined as the blank character which is less than any other character (More info).


&nbsp;
Constraints:


	1 &lt;= words.length &lt;= 100
	1 &lt;= words[i].length &lt;= 20
	order.length == 26
	All characters in words[i] and order are English lowercase letters.


class Solution:
    def isAlienSorted(self, words: List[str], order: str) -> bool:
        order_index = {key:index for index, key in enumerate(order)}

        for i in range(len(words)-1):
           w1,w2 = words[i] , words[i + 1]
           for j in range(len(w1)):
                if j == len(w2):
                    return False
                if w1[j] != w2[j]:
                    if order_index.get(w2[j]) < order_index.get(w1[j]):
                        return False
                    break
        return True
class Solution {
    public boolean isAlienSorted(String[] words, String order) {
        int val=1;
        int[] alp = new int[26];

        for(int i=0;i<order.length();i++) {
            alp[order.charAt(i)-'a']=val;
            val++;
        }
        int flag=0; // if second string is shorter than first then this will be used to check if second is a subset of first starting from the beginning

        for(int i=0;i<words.length-1;i++) {
            flag=0;
            for(int j=0; j<words[i].length() && j<words[i+1].length(); j++) {
                if(words[i].charAt(j) == words[i+1].charAt(j)) {
                    continue;
                }
                if(alp[words[i].charAt(j)-'a'] > alp[words[i+1].charAt(j)-'a']) {
                    return false;
                } else if(alp[words[i].charAt(j)-'a'] < alp[words[i+1].charAt(j)-'a']) {
                    flag=1;
                    break;
                }
            }
            if(flag==0 && words[i].length()>words[i+1].length()) {
                return false; // if second word is sub string of first word starting from the beginning, return false.
            }
        }

        return true;
    }
}
class Solution {
public:
    bool isAlienSorted(vector<string>& words, string order)
    {
        unordered_map<char,char> m;
        for(int i=0;i<26;i++)
        {
            m[order[i]]=i+'a';
        }
        for(auto &w:words)
        {
            for(auto &ch:w)
            {
                ch=m[ch];
            }
        }
        return is_sorted(words.begin(),words.end());// check sorting

    }
};
//if you like the solution plz upvote;
/**
 * @param {string[]} words
 * @param {string} order
 * @return {boolean}
 */
var isAlienSorted = function(words, order) {
    let map = {}
    for(let i = 0; i < 26; i++){
        map[order[i]] = i
    }
    for(let i = 0; i < words.length - 1; i++){
        for(let j = 0; j < words[i].length; j++){
            if(j === words[i+1].length) return false
            if(words[i][j] !== words[i+1][j]){
                if(map[words[i+1][j]] < map[words[i][j]]) return false
                break
            }
        }
    }
    return true
};
Verifying an Alien Dictionary