• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
January 17, 2024 |530 Views
SDE Sheet - Alien Dictionary
  Share  2 Likes
Description
Discussion

This video is part of Graph section under GFG SDE Sheet.

In this problem, we are given a sorted dictionary of an alien language having N words and k starting alphabets of standard dictionary. Find the order of characters in the alien language.
Note: Many orders may be possible for a particular test case, thus you may return any valid order and output will be 1 if the order of string returned by the function is correct else 0 denoting incorrect string returned.

Example :

Input: 
N = 5, K = 4
dict = {"baa","abcd","abca","cab","cad"}
Output:
1

Explanation:
Here order of characters is 'b', 'd', 'a', 'c' Note that words are sorted and in the given language "baa" comes before "abcd", therefore 'b' is before 'a' in output. Similarly we can find other orders.

Try it out before watching the implementation of the problem in the video. We recommend watching the video, even if you can solve the problem. You may discover something new. All the best!!!

Do check out:-
Article: https://www.geeksforgeeks.org/given-sorted-dictionary-find-precedence-characters/
Problem: https://www.geeksforgeeks.org/problems/alien-dictionary/1
SDE Sheet Link: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/

Read More