Team Ai
Datasetpublic

FPEvalRepoPublic/LeetCodeMetaData

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes399downloads
maximum-enemy-forts-that-can-be-captured.json34 linesDownload Raw Back to root
1{2  "id": 2602,3  "name": "maximum-enemy-forts-that-can-be-captured",4  "difficulty": "Easy",5  "link": "https://leetcode.com/problems/maximum-enemy-forts-that-can-be-captured/",6  "date": "2022-12-10",7  "task_description": "You are given a **0-indexed** integer array `forts` of length `n` representing the positions of several forts. `forts[i]` can be `-1`, `0`, or `1` where: `-1` represents there is **no fort** at the `ith` position. `0` indicates there is an **enemy** fort at the `ith` position. `1` indicates the fort at the `ith` the position is under your command. Now you have decided to move your army from one of your forts at position `i` to an empty position `j` such that: `0 <= i, j <= n - 1` The army travels over enemy forts **only**. Formally, for all `k` where `min(i,j) < k < max(i,j)`, `forts[k] == 0.` While moving the army, all the enemy forts that come in the way are **captured**. Return_ the **maximum** number of enemy forts that can be captured_. In case it is **impossible** to move your army, or you do not have any fort under your command, return `0`_._ **Example 1:** ``` **Input:** forts = [1,0,0,-1,0,0,0,0,1] **Output:** 4 **Explanation:** - Moving the army from position 0 to position 3 captures 2 enemy forts, at 1 and 2. - Moving the army from position 8 to position 3 captures 4 enemy forts. Since 4 is the maximum number of enemy forts that can be captured, we return 4. ``` **Example 2:** ``` **Input:** forts = [0,0,1,-1] **Output:** 0 **Explanation:** Since no enemy fort can be captured, 0 is returned. ``` **Constraints:** `1 <= forts.length <= 1000` `-1 <= forts[i] <= 1`",8  "test_case": [9    {10      "label": "Example 1",11      "input": "forts = [1,0,0,-1,0,0,0,0,1]",12      "output": "4 "13    },14    {15      "label": "Example 2",16      "input": "forts = [0,0,1,-1]",17      "output": "0 "18    }19  ],20  "constraints": [21    "-1 represents there is no fort at the ith position.",22    "0 indicates there is an enemy fort at the ith position.",23    "1 indicates the fort at the ith the position is under your command.",24    "0 <= i, j <= n - 1",25    "The army travels over enemy forts only. Formally, for all k where min(i,j) < k < max(i,j), forts[k] == 0.",26    "1 <= forts.length <= 1000",27    "-1 <= forts[i] <= 1"28  ],29  "python_template": "class Solution(object):\n    def captureForts(self, forts):\n        \"\"\"\n        :type forts: List[int]\n        :rtype: int\n        \"\"\"\n        ",30  "java_template": "class Solution {\n    public int captureForts(int[] forts) {\n        \n    }\n}",31  "metadata": {32    "func_name": "captureForts"33  }34}