Skip to content

Commit 4012361

Browse files
committed
Mar 19
1 parent 307be89 commit 4012361

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution:
2+
def minOperations(self, nums: list[int]) -> int:
3+
n = len(nums)
4+
flips = 0
5+
for i in range(n - 2):
6+
if nums[i] == 1:
7+
continue
8+
nums[i] ^= 1
9+
nums[i + 1] ^= 1
10+
nums[i + 2] ^= 1
11+
flips += 1
12+
return flips if nums[-2] == 1 and nums[-1] == 1 else -1
13+
14+
15+
def main():
16+
nums = [0, 1, 1, 1, 0, 0]
17+
assert Solution().minOperations(nums) == 3
18+
19+
nums = [0, 1, 1, 1]
20+
assert Solution().minOperations(nums) == -1
21+
22+
23+
if __name__ == '__main__':
24+
main()

2025-03-March-LeetCoding-Challenge/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
| March 16 | [2594. Minimum Time to Repair Cars](https://leetcode.com/problems/minimum-time-to-repair-cars/) | Medium | Unsolved |
2323
| March 17 | [2206. Divide Array Into Equal Pairs](https://leetcode.com/problems/divide-array-into-equal-pairs/) | Easy | Solved |
2424
| March 18 | [2401. Longest Nice Subarray](https://leetcode.com/problems/longest-nice-subarray/) | Medium | Unsolved |
25-
| March 19 | []() | | |
25+
| March 19 | [3191. Minimum Operations to Make Binary Array Elements Equal to One I](https://leetcode.com/problems/minimum-operations-to-make-binary-array-elements-equal-to-one-i/) | Medium | Solved |
2626
| March 20 | []() | | |
2727
| March 21 | []() | | |
2828
| March 22 | []() | | |
@@ -41,5 +41,5 @@
4141
| Level | Problems | Solved | Unsolved |
4242
| --- | --- | --- | --- |
4343
| Easy | 6 | 6 | 0 |
44-
| Medium | 12 | 5 | 7 |
44+
| Medium | 13 | 6 | 7 |
4545
| Hard | 0 | 0 | 0 |

0 commit comments

Comments
 (0)