Data Structures & AlgorithmsVery hardProduct company OA

An alien language uses only the letters a, b, c, d. The words bca, bcd, ad, ac, dc are listed in sorted order. Building an edge from each first differing letter pair and topologically sorting, what is the letter order?

  1. A. a < b < c < d
  2. B. b < a < d < c
  3. C. b < a < c < d
  4. D. b < d < a < c

Correct answer: B. b < a < d < c

Adjacent pairs give: bca/bcd → a < d; bcd/ad → b < a; ad/ac → d < c; ac/dc → a < d. The chain b < a < d < c is forced and unique. Comparing whole words or non-adjacent pairs adds nothing new; ordering c before d ignores ad/ac.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic