Back
Close

Longest snake

Statement

 Goal

You have found a rectangular box made of n lines with snakes jammed in it, and you want to know what is the length of the longest snake.

The box is perfectly filled with snakes from top to bottom in a zigzag manner, starting at the top left facing right. The snakes have a generally horizontal orientation, and switch direction at the left and right edges of the box. A snake may span across more than one line.

Each snake has a tail: < or > depending on the direction; a body consisting of at least one =, and a head: o.

Example:
>===o>====
o=<o=<o===

There are 4 snakes, in order of appearance:
>===o
>=======o
>=o
>=o

The answer is then 9, corresponding to the size of the second snake.
Input
Line 1: An integer n for the number of lines that make up the snake box.
Next n lines: The snake box.
Output
An integer representing the size of the longest snake in the box.
Constraints
Every snake has a body consisting of at least one =.
0 < n < 100
The width of the box is constant.
0 < width < 50
Example
Input
1
>=====o
Output
7

Game modes
Fastest, Shortest, Reverse

Test cases
Just one Test
Input
1 >=====o
Output
7

Just one val Validator
Input
1 >===o
Output
5

Tidy twos Test
Input
2 >==o>=o o=====<
Output
7

Tidy twos val Validator
Input
2 >==o>==o o======<
Output
8

Switching Test
Input
2 >==== o=<o=
Output
7

Switching val Validator
Input
2 >====== o==<o==
Output
10

Example-like Test
Input
2 >==o>== o==<o==
Output
6

Example-like val Validator
Input
2 >=o>===o>= o===<o=<o=
Output
5

Trimming Test
Input
3 >=====o>==== ============ =======o>==o
Output
25

Trimming val Validator
Input
3 >=o>==o>==== ============ =====o>====o
Output
23

Longer Test
Input
30 >=====o>== =====<o=== =====o>=o> =<o==<o=== =======o>= =====<o=== =====o>=== o=====<o== >==o>=o>=o ======<o=< ====o>=o>= =====<o=== o>======== ======<o== =o>===o>== ===<o===== ==o>====== =====<o=== ===o>===== ====<o==== ====o>==o> =<o======= ========== o=======<o >========o ====<o===< ===o>===== ===<o=<o== ========o> o=====<o==
Output
13

Longer val Validator
Input
29 >======o>= ======<o== ====o>==== ===<o===== =======o>= o====<o=== >=o>====o> ========== o>==o>=o>= o==<o===== >==o>====o o========< >===o>==== <o===<o=== =======o>= ===<o===== =o>======= =<o====<o= ======o>=o =========< =o>======= <o====<o== ========== o=======<o >====o>=== =<o======= o>======== ===<o===<o o>====o>=o
Output
12

Many Test
Input
85 >========= ======<o== =========o o========< >========= =<o======= ======o>== ========== =====o>=== ===<o===<o ====o>==== ======<o== ===o>===== ========== ===o>===== =====<o=== ========== ======<o== ==o>===o>= =<o======= =====o>=== ===<o===== =======o>= ========== ==o>====== ==<o====== =======o>= o========= >========= ==<o====== ========== ===<o===== ========== ====<o=<o= =o>=o>==== ========== o>======== <o======== ========== <o======== ====o>==== =<o======= ======o>== ======<o== =o>======= <o======== ========== ==<o====== ========== =====<o=== o>=======o o=<o=====< >========= ====<o==== o>======== ==<o====== ========== ====<o==== ======o>== o========= >========= ==<o====== ===o>===o> ===<o===== ========== =====<o=== ===o>===== ========== =o>======= ========== =o>======= ========== =o>======= ==<o====== ======o>== ========== ======o>== =<o======= ======o>== <o======== =========o =========< =======o>= ========== ======o>=o
Output
20

Many val Validator
Input
80 >========= ======<o== ========== =======<o= ===o>===== ========== ===o>===== <o======== ========== o====<o=== >========= =<o=<o==== ========o> =======<o= ===o>===== o========= >======o>= ========== ===o>===== ==<o====<o ========== =======<o= ========== ==<o==<o== ===o>===== ========== =o>==o>=== ========== ====o>==== ========== o>=======o =========< =====o>=== =======<o= =====o>=== =====<o=== =====o>=== =======<o= ===o>===== ========== ===o>===== ======<o== o>======o> ========== ========o> ========== ====o>==== ========== ==o>====== ========<o =========o =========< =o>======= =======<o= =====o>=o> ========== ===o>===== <o======== =o>======= o========= >========= ========<o =o>======= o========= >========= =<o=====<o ===o>===== ========== ==o>====== =====<o=== =====o>=== ========== ====o>=o>= ====<o=<o= o>======o> ========== o>======== ===<o===<o ========== o======<o=
Output
21

Solution language

Solution

Stub generator input