Loading...
You are given an array of lowercase words and a string order that is a permutation of the 26 lowercase letters. order defines a custom alphabet: the letter order[i] is smaller than order[j] whenever i < j.
Return true if words is sorted in non-decreasing lexicographic order under this custom alphabet, and false otherwise. As usual, when one word is a proper prefix of the next, the shorter word must come first.
Input: words = ["hello","leetcode"], order = "hlabcdefgijkmnopqrstuvwxyz"
Output: true
Explanation: h comes before l in this alphabet, so the two words are in order.
Input: words = ["word","world","row"], order = "worldabcefghijkmnpqstuvxyz"
Output: false
Explanation: At the first difference between "word" and "world", d comes after l in this alphabet, so words[0] > words[1].
Input: words = ["apple","app"], order = "abcdefghijklmnopqrstuvwxyz"
Output: false
Explanation: "app" is a proper prefix of "apple", so it must come first.
words.length ≤100words[i].length ≤20order.length == 26words[i] and order are lowercase English lettersClick "Run" to test with sample cases or "Submit" to run all tests.