Maximum Enemy Forts That Can Be Captured Problem
Maximum Enemy Forts That Can Be Captured Problem — ExecCode Easy DSA Practice
Solve the Maximum Enemy Forts That Can Be Captured problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given a 0-indexed integer array forts of length n representing the positions of several forts. Your task is to compute the required answer and return the maximum number of enemy forts that can be captured. forts[i] can be -1, 0, or 1 where: - -1 represents there is no fort at the i^th position. - 0 indicates there is an enemy fort at the i^th position. - 1 indicates the fort at the i^th the position is under your command.
Examples
Input {"forts": [1, 0, 1, 0, -1, 0, 1]}; Output 1. Input {"forts": [-1, 0, 0, 0, 0, 1]}; Output 4. Input {"forts": [0, 0, 0, 0, 0, 0, 0]}; Output 0
Constraints
1 <= forts.length <= 1000 -1 <= forts[i] <= 1
Practice Maximum Enemy Forts That Can Be Captured free on ExecCode. Browse DSA problems, topic map, and placement guides.