Close
Topic list
Alien dictionary
HARD
46 mins
Strings
Sorting
Graph
Arrays
Topics (Covered in this problem)
Problem solved
Skill meter
Strings
-
-
Sorting
-
-
Graph
-
-
Arrays
-
-
Other topics
Problem solved
Skill meter
Matrices (2D Arrays)
-
-
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# Alien dictionary

Contributed by
Nishant Chitkara
Hard
0/120
Avg time to solve 46 mins
Success Rate 50 %
Share

## Problem Statement

#### You have been given a sorted (lexical order) dictionary of an alien language. Write a function that finds the order of characters in the alien language. This dictionary will be given to you in the form of an array of strings called 'dictionary,' of size 'N.'

##### Example :
``````If the dictionary consists of the following words:-
["caa", "aaa", "aab"]
then, the order of alphabets are -
['c', 'a', 'b']
``````
##### Note:
``````If the language consists of four letters, the four letters should be the starting four letters of the English language. However, their order might differ in the alien language.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1 :
``````2
3
a aa aaa
3
a b c
``````
##### Sample Output 1 :
``````true
true
``````
##### Explanation For Sample Output 1 :
``````For the first test case, the words are 'a', 'aa', and 'aaa'. Since the only unique character here is 'a', so the array to be returned will just be ['a']. The 'true' that is being printed just signifies that the output returned by the function is valid.

For the second test case, the words are 'a', 'b', and 'c'. The unique characters here are 'a', 'b', and 'c' (in that order), so the array to be returned will be ['a', 'b', 'c']
``````
##### Sample Input 2 :
``````2
3
caa aaa aab
2
aa aab
``````
##### Sample Output 2 :
``````true
true
``````
Auto
Console