Problem Statement | |||||||||||||
Given a base word, original, and a compound word, compound, decide if the compound word is valid. A compound word is valid if and only if it is comprised solely of a concatenation of prefixes and/or suffixes of original. That is, if the compound word can be partitioned into N parts, such that each part is equal to either a prefix or a suffix of original, then it is valid. If the word is invalid, return -1. Otherwise, return the minimum value of N for which this is possible. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | The entire base word original is considered a valid prefix/suffix of itself. See example 3. | ||||||||||||
Constraints | |||||||||||||
| - | original will contain between 1 and 50 characters, inclusive. | ||||||||||||
| - | original will consist only of uppercase letters (A-Z). | ||||||||||||
| - | compound will contain between 0 and 50 characters, inclusive. | ||||||||||||
| - | compound will consist only of uppercase letters (A-Z). | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
| 4) | |||||||||||||
| |||||||||||||
| 5) | |||||||||||||
| |||||||||||||
| 6) | |||||||||||||
| |||||||||||||