Associated Course(s):
Must Do Interview Preparation

Given a sorted dictionary of an alien language having N words and k starting alphabets of standard dictionary the task is to complete the function which returns a string denoting the order of characters in the language.

**Note:** Many orders may be possible for a particular test case, thus you may return any valid order.

**Examples:**

Input: Dict[] = { "baa", "abcd", "abca", "cab", "cad" }, k = 4

Output: Function returns "bdac"

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.

Input: Dict[] = { "caa", "aaa", "aab" }, k = 3

Output: Function returns "cab"

**Input:**

The first line of input contains an integer T denoting the no of test cases. Then T test cases follow. Each test case contains an integer N and k denoting the size of the dictionary. Then in the next line are sorted space separated values of the alien dictionary.

**Output:**

For each test case in a new line output will be 1 if the order of string returned by the function is correct else 0 denoting incorrect string returned.

**Constraints:**

1 <= T <= 200

1 <= N <= 100

1 <= k <= 26

1 <= Length of words <= 1000

**Example:
Input:**

2

5 4

baa abcd abca cab cad

3 3

caa aaa aab

**Output:**

1

1

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

the_coder95 | 465 |

thanuvinu94 | 388 |

adityasuman2025 | 305 |

Senbonzakura_Kageyoshi | 297 |

PrakharBansal1 | 274 |

the_coder95 | 1691 |

RishabhTanwar1 | 1110 |

thanuvinu94 | 1064 |

samay_kam_hai | 724 |

themanhasnoname | 620 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4897 |

Quandray | 4547 |

Login to report an issue on this page.