Skip to content

Practice Maximum Enemy Forts That Can Be Captured

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#2511
LeetCode Problem

Maximum Enemy Forts That Can Be Captured

Problem Statement

forts uses 1 for a fort you command, 0 for an enemy fort and -1 for an empty position. Move from one of your forts to an empty position only when every position strictly between them is an enemy fort. All intervening enemy forts are captured. Return the greatest number captured by one such move, or 0 if no capture is possible.

Source: Maximum Enemy Forts That Can Be Captured on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
forts = [1,0,0,-1,0,0,0,0,1]
Output
4

# Example 2

Input
forts = [0,0,1,-1]
Output
0

Constraints

1 <= forts.length <= 1000
-1 <= forts[i] <= 1

Related LeetCode Problems

Practice more problems similar to Maximum Enemy Forts That Can Be Captured.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.