Problem Statement
You have a rectangular box with height 1 cm and width N cm. Some parts of the box are already full and the others are empty.
You are going to put a rectangular block with height 1 cm in this box. You can put a box with width k cm if there exists a contiguous empty section with width k cm or more.
You are given a String s of length N. The section between i cm and (i+1) cm from the left end of the box is already full if the i-th character of s is 'X', and it is empty if the i-th character of s is '.' (0-based). Return the maximum possible width of the block you can put in the box. If you can't put any block in the box, return 0 instead.
You are going to put a rectangular block with height 1 cm in this box. You can put a box with width k cm if there exists a contiguous empty section with width k cm or more.
You are given a String s of length N. The section between i cm and (i+1) cm from the left end of the box is already full if the i-th character of s is 'X', and it is empty if the i-th character of s is '.' (0-based). Return the maximum possible width of the block you can put in the box. If you can't put any block in the box, return 0 instead.
Definition
- Class:
- BlockPutting
- Method:
- getmax
- Parameters:
- String
- Returns:
- int
- Method signature:
- int getmax(String s)
- (be sure your method is public)
Constraints
- The length of s will be between 1 and 50, inclusive.
- Each character in s will be 'X' or '.'.
Examples
"..X...X"
Returns: 3
The best solution is to put a 3 cm width block into the section between 3 cm and 6 cm from the left end of the box."....."
Returns: 5
This box is empty, so you can put a 5 cm width block."XXXXXX"
Returns: 0
This box is already full, so you can't put a block in this box."..XX..XX..XX..XX..XX..XX..XX..XX..XX..XX..."
Returns: 3
".........X.X........X..XXXXXX........X..."
Returns: 9