IITKESO207SPA4A - Lexicographic Permutations
Given a list of N names, find a permutation of characters of the alphabet such that these N names are in lexicographic order with respect to that permutation. If no such permutation exists, print "IMPOSSIBLE".
Lexicographical order is defined in the following way : when we compare two strings s and t, first we find teh leftmost position with differeing characters. If there is no such poisition, the shortest string is lexicographically lower. Otherwise, we compare characters according to their order in the alphabet.
An integer N for the number of names, followed by n lines each containing a string of names all in small characters.
Print the permutation of the characters such that these names are in lexicographic order. If multiple such permutations are possible, then output the one that is lexicographically lowest.
N will be in the set [1,1000] and each name will have length in the set [1,100]
Somebody who has got it correct, please give the output of the following test case.
@ssuntik, yeah, you are right. I'll modify the answer
abdefgijkmhnopqtucsrlvwxyz and abdefgijkmhucsrlnopqtvwxyz are two possible permutation of characters such that above given names are in lexicographic order , but by definition first one is lower than second and lowest among all. So i think answer for the first or sample test case should be first permutation.
Last edit: 2017-07-09 19:41:30