Problem Statement
Wolf Sothe is playing the game Delaymaster.
In this game, he can create new words according to the following rules:
- For each positive integer n, the string which consists of n copies of 'w', then n copies of 'o', then n copies of 'l', and finally n copies of 'f' is a valid word.
- The concatenation of two valid words is a valid word.
- Only the words that can be obtained by rules 1 and 2 are valid. There are no other valid words.
- By rule 1, "wolf", "wwoollff", and "wwwooolllfff" are valid words.
- Then, by rule 2, "wolfwwoollff" is a valid word.
- By applying rule 2 twice, "wolfwwoollffwolf" is a valid word.
- The string "wfol" is not a valid word (order matters).
- The string "wwolfolf" is not a valid word (we can only concatenate, not insert one word into another).
- The string "wwwoolllfff" is not a valid word (only two 'o's instead of three).
Definition
- Class:
- WolfDelaymaster
- Method:
- check
- Parameters:
- String
- Returns:
- String
- Method signature:
- String check(String str)
- (be sure your method is public)
Constraints
- str will contain between 1 and 50 characters, inclusive.
- Each character in str will be 'w', 'o', 'l' or 'f'.
Examples
"wolf"
Returns: "VALID"
The first valid word from the examples in the problem statement."wwolfolf"
Returns: "INVALID"
The second invalid word from the examples in the problem statement."wolfwwoollffwwwooolllfffwwwwoooollllffff"
Returns: "VALID"
"flowolf"
Returns: "INVALID"