After attempting to program in Grass for the entire morning, you decide to go outside and mow some real grass. The grass can be viewed as a string consisting exclusively of the following characters:
w denotes tall grass which takes \$ 1 \$ unit of energy to mow.
W denotes extremely tall grass which takes \$ 2 \$ units of energy to mow. Lastly
v denotes short grass which does not need to be mowed.
You decide to mow the grass from left to right (beginning to the end of the string). However, every time you encouter a
v (short grass), you stop to take a break to replenish your energy, before carrying on with the mowing. Your task is to calculate the maximum amount of energy expended while mowing. In other words, find the maximum total energy of mowing a patch of grass, that of which does not contain
In the example input below, the answer is \$ 8 \$. Although the patch
wwwwwww is a longer patch of grass, it only costs \$ 7 \$ units of energy, whereas the optimal patch
WWWW expends \$ 2 \times 4 = 8 \$ units of energy.
Input: WwwvWWWWvvwwwwwwwvWwWw Output: 8
Here is an example Python program -> Try It Online!.
WwwvWWWWvvwwwwwwwvWwWw -> 8 w -> 1 W -> 2 vwww -> 3 vWWW -> 6 v -> 0 vvvvvvv -> 0 vwvWvwvWv -> 2 vWWWWWWWWWWvwwwwwwwwwwwwwwwwwwwwwv -> 21 vWWWWWWWWWWvwwwwwwwwwwwwwwwwwwwv -> 20 vvWvv -> 2
This is code-golf, so the shortest code in bytes wins!
vdoesn't look much shorter than