Ninja and Alien Language Order Problem

An alien dropped its dictionary while visiting Earth. The Ninja wants to determine the order of characters used in the alien language, based on the given list of words from the alien's dictionary.

Example:

Input:
words = ["baa", "abcd", "abca", "cab", "cad"]
Output:
Order: "bdac"
Explanation:

The order of characters is derived from the following constraints based on the words' order:
"baa" before "abcd": 'b' comes before 'a'.
"abcd" before "abca": 'd' comes before 'a'.
Resulting in the order 'b', 'd', 'a', 'c'.

Constraints:

  • The list of words may have more than one valid order; return the smallest lexicographical order.
  • Return an empty string if there is no valid order.
  • 1 <= T <= 10
  • 1 <= N <= 300
  • 0 <= size of a word <= 100
  • Time limit: 1 sec
AnswerBot
4mo

Determine the order of characters in an alien language based on a list of words from the alien's dictionary.

  • Create a graph data structure to represent the relationships between characters in the words...read more

Help your peers!
Select
Add answer anonymously...

Accenture Associate Software Engineer interview questions & answers

An Associate Software Engineer was asked 2w agoQ. Which technology stack have you worked with?
An Associate Software Engineer was asked 3w agoQ. What is NLP?
An Associate Software Engineer was asked 4w agoQ. Explain the concepts of OOPs.

Popular interview questions of Associate Software Engineer

An Associate Software Engineer was asked 2w agoQ1. Which technology stack have you worked with?
An Associate Software Engineer was asked 3w agoQ2. What is NLP?
An Associate Software Engineer was asked 4w agoQ3. Explain the concepts of OOPs.

Top HR questions asked in Accenture Associate Software Engineer

An Associate Software Engineer was asked 2w agoQ1. Have you ever encountered a project issue with a teammate who unexpectedly left,...read more
An Associate Software Engineer was asked 2w agoQ2. Can you share something about yourself that is not included in your resume?
An Associate Software Engineer was asked 1mo agoQ3. What challenges did you face as a team leader during the project?
Accenture Associate Software Engineer 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