Alien Dictionary

Topological Sort DSA practice problem on Onlearn.

Difficulty: hard.

Topics: Find the order of characters in an alien language given a sorted dictionary, Graph, Directed Graph, Adjacency List, Graph Traversal, Breadth-First Search, Queue, Topological Sorting, Cycle Detection, Time Complexity, Space Complexity, graph representation, topological sort, string operations, graph algorithms, graph properties, bfs, Cycle Detection in Directed Graphs.

Alien Dictionary Given a sorted dictionary of an alien language having N words and an integer K representing the number of distinct lowercase English characters present in the alien language's alphabet. Your task is to find the order of characters in the alien language. Note: Multiple valid orders may be possible for a particular test case; you may return any valid order. Input Specification: The first line contains two integers N and K, representing the number of words in the dictionary and the total number of distinct characters in the alien alphabet, respectively. The next N lines contain strings, where dict[i] is the i th word in the alien dictionary. Output Specification: Return a string representing the order of characters in the alien language. Constraints: Characters will be lowercase English letters ('a' through the K th letter). Sample Test Cases: Example 1: Example 2: