All submissions | Best solutions | Back to list |
IITKESO207SPA4A - Lexicographic Permutations |
Problem description
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.
Input format
An integer N for the number of names, followed by n lines each containing a string of names all in small characters.
Output format
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.
Constraints :
N will be in the set [1,1000] and each name will have length in the set [1,100]
Sample input
7
motwani
hopcroft
ullman
cormen
stein
rivest
leiserson
Sample output
abdefgijkmhnopqtucsrlvwxyz
Added by: | Programming Club, IITK |
Date: | 2017-07-06 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
Resource: | ESO207, IIT Kanpur Summer Semester 2017 |
hide comments