TopCoder problem "Snaky" used in TCO07 Qual 1 (Division I Level One)



Problem Statement

    
       xxxxx...
       ....xxxx
       .x.....x
       .xxxxxxx
Your are given a picture of a snake. Lowercase 'x' characters indicate parts of the snake, and '.' characters represent empty areas. The snake consists of a sequence of horizontal and vertical segments. Successive segments in the snake share an 'x', which is considered to be in both segments. No two 'x's from different segments of the snake are horizontally or vertically adjacent.

Given a String[] snake, return the length of the longest segment in the snake. The picture is formed using successive elements of snake as successive rows in the picure.

 

Definition

    
Class:Snaky
Method:longest
Parameters:String[]
Returns:int
Method signature:int longest(String[] snake)
(be sure your method is public)
    
 

Constraints

-snake contains between 1 and 50 elements, inclusive.
-Each element of snake contains the same number of characters.
-Each element of snake contains between 1 and 50 characters, inclusive.
-Each character in each element of snake is a period ('.') or a lowercase 'x'.
-If two 'x's are adjacent to each other in the picture, they are in the same segment.
-The picture shows just one connected snake, using at least 2 'x's.
 

Examples

0)
    
{"x.xxx.xxx",
 "x.x.x.x.x",
 "xxx.xxx.x"}
Returns: 3
This snake consists of 9 segments, each of length 3.
1)
    
{"xxxx..",
 "...x..",
 "...x..",
 "......"}
Returns: 4
One segment is length 4, the other is length 3.
2)
    
{"...x................",
 "...x................",
 "....................",
 "...................."}
Returns: 2

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=7634

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10730&pm=7634

Writer:

dgoodman

Testers:

PabloGilberto , brett1479 , legakis , Olexiy

Problem categories:

Simple Search, Iteration