Skip to content

Missing Test Case - 3191. Minimum Operations to Make Binary Array Elements Equal to One I #27951

@FardinJim27

Description

@FardinJim27

LeetCode Username

FardinJim7

Problem Number, Title, and Link

  1. 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
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions