Grokking the Coding Interview: Patterns for Coding Questions

0% completed

Alien Dictionary (hard)

Problem Statement

There is a dictionary containing words from an alien language for which we don’t know the ordering of the letters.

Given a list of strings words from the alien language's dictionary. All strings in words are sorted lexicographically by the rules of this new language.

Return a string of the unique letters in the new alien language sorted in lexicographically increasing order by the new language's rules.

It is given that the input is a valid dictionary and there exists an ordering among its letters.

Example 1:

.....

.....

.....

Like the course? Get enrolled and start learning!
J

John Smith

· 4 years ago

for alien dictionary, I believe they added extra test cases that makes this solution fail. I copy-pasted it over too

Show 6 replies
M

Mikhail Putilov

· 3 years ago

Am I the only one who is challenged understanding the problem statement?

Show 1 reply
R

Ray

· 4 years ago

For lols, here's a wrong solution that returns the correct strings (bac, cab, ywxz)

function find_order(words) {
let letters = new Set()
for (const word of words) {
let characters = word.split('')
letters = new Set([...letters, ...characters])
}
return Array.from(letters).join('')
}

Obviously it doesn't solve anything :)