Fix-Free Check
InterviewTime limit1sMemory limit128 MB
For each triple of words, decide whether no word is a prefix or suffix of another, printing Yes or No.
- Level
Easy3 of 10
- Topics
- String, Brute force, Implementation, Sorting
- Solved
- No attempts yet
Problem
A collection of words is prefix-free if no word is a prefix of any other word. A collection of words is suffix-free if no word is a suffix of any other word. A collection of words is fix-free if it is both prefix-free and suffix-free.
In this problem, a word is a sequence of lower-case letters whose length is between and . A word is a prefix of a word if, for some , consists of the first characters of in order. For example, the prefixes of the word cat are c, ca, and cat. Similarly, a word is a suffix of if consists of the last characters of in order.
Input
The first line contains the number of collections . The following lines describe the collections in order, with three words per collection and one word per line. That is, lines , , and form the first collection, lines , , and form the second collection, and so on.
Output
For each collection, print one line containing Yes if that collection is fix-free, or No otherwise. Print lines in the order the collections are given.