Loading...
You are given an array of strings words, using the lowercase English letters, where the alphabet is ordered by some unknown permutation. The list is claimed to be sorted lexicographically according to that unknown ordering, with the usual rule that a word precedes any longer word it is a prefix of.
Return a string containing every distinct letter that appears in words, each exactly once, arranged in an order consistent with the claimed sorting.
a to z order."".Input: words = ["wrt","wrf","er","ett","rftt"]
Output: "wertf"
Explanation: Adjacent pairs give t<f, w<e, r<t, e<r, which pins the unique order w, e, r, t, f.
Input: words = ["z","x"]
Output: "zx"
Explanation: The only constraint is z<x.
Input: words = ["z","x","z"]
Output: ""
Explanation: z<x and x<z contradict each other.
words.length ≤100words[i].length ≤100words[i] consists of lowercase English letters.Click "Run" to test with sample cases or "Submit" to run all tests.