Problem Statement
When a stone is thrown across water, sometimes it will land on the water and bounce rather than falling in right away. Suppose that a stone is thrown a distance of n. On each successive bounce it will travel half the distance as the previous bounce (rounded down to the nearest integer). When it can not travel any further, it falls into the water. If, at any point, the stone lands on an obstruction rather than water, it will not bounce, but will simply deflect and fall into the water. Please look at the figure for further clarification (with black, red and green cells representing banks, obstructions and free water respectively). So, if the stone is thrown a distance 7, it will bounce and travel a distance of 3, then finally a distance of 1, having travelled a total distance of 11 (the green path in the figure). If a stone is thrown a distance of 8, it will reach the opposite bank, and if thrown at distances of 2 or 6 it will hit an obstruction during its travel. These are the three red paths in the figure.
You are given a String water. An 'X' represents an obstruction, while a '.' represents water free from obstruction. You are to return an int representing the maximum distance a stone can travel and finally fall in the water, without hitting any obstructions, and without reaching the opposite bank (going beyond the end of the string). You may choose any initial distance for the throw, which starts from the left side of the string. A distance of 1 is the first character of the string, etc. If no initial throw will result in the stone landing in the water without hitting an obstruction, return 0.
Definition
Class: 
SkipStones 
Method: 
maxDistance 
Parameters: 
String 
Returns: 
int 
Method signature: 
int maxDistance(String water) 
(be sure your method is public) 
Notes

Obstructions are at water level, so the stone will not hit any obstructions while it's in the air.
Constraints

water will contain between 1 and 50 elements, inclusive.

Each element of water will contain between 1 and 50 characters, inclusive.

Each character of each element of water will be 'X' or '.'.
Examples
0)
 
Returns: 11  

1)
 
Returns: 3  

2)
 
Returns: 22  

3)
 
Returns: 15  
