Alien Dictionary Problem Statement

You are provided with a sorted dictionary (by lexical order) in an alien language. Your task is to determine the character order of the alien language from this dictionary. The dictionary is provided as an array of strings named 'dictionary' with a size 'N'.

Input:

The first line comprises an integer 't', representing the number of test cases or queries. Each test case includes the following:
• An integer 'N' indicating the number of words in the alien dictionary.
• The next line consists of 'N' space-separated strings, each representing a word in the alien dictionary.

Output:

For each test case, return a list of characters indicating their order in the alien language. The initial element denotes the first letter in the alien language, followed by the second, and so on. You must return the character array without printing anything. Each test case output should be displayed separately.

Example:

Input:
["caa", "aaa", "aab"]
Output:
['c', 'a', 'b']

Constraints:

  • 1 ≤ t ≤ 100
  • 0 ≤ N ≤ 105
  • 0 ≤ Length of ARR[i] ≤ 105
  • Time Limit: 1 sec

Note:

The alien language comprises only lowercase letters, although their order might not follow the English alphabet. If the language comprises four letters, they will be the first four of the English alphabet but may appear in a different order in the alien language.
AnswerBot
1y

The task is to find the order of characters in an alien language given a sorted dictionary.

  • The order of characters can be determined by comparing adjacent words in the dictionary.

  • Create a graph where ...read more

Help your peers!
Add answer anonymously...
AVL Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter