line:
- 1 is one of your forts;
- 0 is an enemy fort;
- -1 is an empty cell.
You send an army from one of your forts at cell i to an empty cell j, to the left or to the right. The army may only pass over enemy forts: every cell strictly between i and j must be 0. Every enemy fort it passes is captured.
Return the largest number of enemy forts a single such march can capture. If no march is possible (or you have no forts at all), return 0.line=[0, 1, 0, 0, 0, -1, 0, 1] → 3
From the fort at cell 1 the army reaches the empty cell 5, capturing three enemy forts (cells 2, 3 and 4). From the fort at cell 7 to cell 5 it captures only one. The answer is 3.
line=[1, 0, 1, 0, 0] → 0
There is no empty cell to march to, so the answer is 0.
line=[-1, 1, 0, 0] → 0
The army can step into the empty cell 0 next to it, but there are no enemy forts on the way. The answer is 0.
line[i] is -1, 0 or 1line=[0, 1, 0, 0, 0, -1, 0, 1]
3
Run checks the first 3 tests in your browser. Submit checks all 103 tests on the server, hidden ones included.