forked from keshavnandan/Topcoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWolfDelaymaster.txt
65 lines (40 loc) · 1.61 KB
/
WolfDelaymaster.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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.
Thus, for example:
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).
You are given a string str.
Return "VALID" if str is a valid word and "INVALID" otherwise.
Note that the return value is case-sensitive: you must return the strings "VALID" and "INVALID" in all-uppercase.
DEFINITION
Class:WolfDelaymaster
Method:check
Parameters:string
Returns:string
Method signature:string check(string str)
CONSTRAINTS
-str will contain between 1 and 50 characters, inclusive.
-Each character in str will be 'w', 'o', 'l' or 'f'.
EXAMPLES
0)
"wolf"
Returns: "VALID"
The first valid word from the examples in the problem statement.
1)
"wwolfolf"
Returns: "INVALID"
The second invalid word from the examples in the problem statement.
2)
"wolfwwoollffwwwooolllfffwwwwoooollllffff"
Returns: "VALID"
3)
"flowolf"
Returns: "INVALID"