Problem Statement | |||||||||||||
A prefix-free set is a set of words such that no element in the set is a prefix of another element of the set. For example {"hello"} , {"hello", "goodbye", "giant", "hi"} and the empty set are examples of prefix-free sets. On the other hand, {"hello","hell"} and {"great","gig","g"} are not prefix-free. You will be given a String[] words containing a set of words, and you must return the number of elements in the largest prefix-free subset of words. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | A prefix of a string is the result of erasing zero or more characters from the right end of that string. | ||||||||||||
Constraints | |||||||||||||
| - | words will contain between 1 and 50 elements, inclusive. | ||||||||||||
| - | Each element of words will contain between 1 and 50 characters, inclusive. | ||||||||||||
| - | Each character of each element of words will be a lowercase letter ('a'-'z'). | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||