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
4mo

Given a sorted alien dictionary in an array of strings, determine the character order of the alien language.

  • Iterate through the words in the dictionary to build a graph of character dependencies.

  • Perfo...read more

Help your peers!
Select
Add answer anonymously...

Cognizant Programmer Analyst Trainee interview questions & answers

A Programmer Analyst Trainee was asked 1w agoQ. Explain the OOPs concepts with examples.
A Programmer Analyst Trainee was asked 2mo agoQ. Tell me about inheritance with an example.
A Programmer Analyst Trainee was asked 2mo agoQ. Write a program to determine if a given year is a leap year.

Popular interview questions of Programmer Analyst Trainee

A Programmer Analyst Trainee was asked 1w agoQ1. Explain the OOPs concepts with examples.
A Programmer Analyst Trainee was asked 2mo agoQ2. Tell me about inheritance with an example.
A Programmer Analyst Trainee was asked 2mo agoQ3. Write a program to determine if a given year is a leap year.

Top HR questions asked in Cognizant Programmer Analyst Trainee

A Programmer Analyst Trainee was asked 5mo agoQ1. Can you tell me about your project?
A Programmer Analyst Trainee was asked 9mo agoQ2. Are you willing to relocate for this job role?
A Programmer Analyst Trainee was asked 10mo agoQ3. Are you willing to work night shifts?
Cognizant Programmer Analyst Trainee Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits