-
Notifications
You must be signed in to change notification settings - Fork 380
Closed
Description
LeetCode Username
FardinJim7
Problem Number, Title, and Link
- 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/?envType=daily-question&envId=2025-03-19
Bug Category
Problem description
Bug Description
N/A
Language Used for Code
Python/Python3
Code used for Submit/Run operation
class Solution:
def minOperations(self, nums: List[int]) -> int:
n = len(nums)
if n < 3:
return -1
ops = 0
for i in range(n - 2):
if nums[i] == 0:
ops += 1
for j in range(i, i + 3):
nums[j] ^= 1 # Flip the element
if nums[n - 2] == 0 or nums[n - 1] == 0:
return -1
return ops
Expected behavior
class Solution:
def minOperations(self, nums: List[int]) -> int:
n = len(nums)
if n < 3:
return -1
ops = 0
for i in range(n - 2):
if nums[i] == 0:
ops += 1
for j in range(i, i + 3):
nums[j] ^= 1 # Flip the element
if nums[n - 2] == 0 or nums[n - 1] == 0:
return -1
return ops
Screenshots
No response
Additional context
No response
Metadata
Metadata
Assignees
Labels
No labels