A localization tool received a list of words that some other system already sorted, using a letter order you don't know. All words use lowercase letters a to z.
Write letterOrder(words) that returns a string containing every distinct letter that appears in words exactly once, in an order consistent with how the words are sorted. When the words don't decide which of several letters comes next, put the one that comes first in the normal alphabet first. If no letter order could produce this sorting, return "".
Words are compared the usual way: at the first position where they differ, the word with the earlier letter comes first. If one word is a prefix of the other, the shorter word must come first.
Input: words = ["bca","aaa","acb"] Output: "bac"
bca before aaa means b comes before a. aaa before acb means a comes before c.
Input: words = ["abc","ab"] Output: ""
A word can't come after its own prefix in any letter order.
1 <= words.length <= 10001 <= words[i].length <= 50Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #443 Decode a Custom Sort Order. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.