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.

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

  • Perform a topological sort ...read more

Help your peers!
Select
Add answer anonymously...

Wipro Software Developer interview questions & answers

A Software Developer was asked 2mo agoQ. What languages have you used?
A Software Developer was asked 2mo agoQ. What are your qualities?
A Software Developer was asked 4mo agoQ. What is an operating system?

Popular interview questions of Software Developer

A Software Developer was asked 5mo agoQ1. What does employee respect mean to you?
A Software Developer was asked 6mo agoQ2. What is eager loading in programming?
A Software Developer was asked 6mo agoQ3. What are the concepts of Object-Oriented Programming (OOP)?

Top HR questions asked in Wipro Software Developer

A Software Developer was asked 1mo agoQ1. Tell me about yourself.
A Software Developer was asked 1mo agoQ2. Tell me about your work experience.
A Software Developer was asked 4mo agoQ3. What is your expected salary?
Wipro Software Developer 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