Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Make Binary Array All Ones I

Minimum Operations to Make Binary Array All Ones I takes a binary array and asks for the fewest flips of three consecutive elements to make every value one, or -1 if impossible.

Statement

You are given a binary array nums.

In one operation, you can choose any 33 consecutive elements from nums and flip each of them, changing every 00 to 11 and every 11 to 00.

Return the minimum number of operations required to make every element in nums equal to 11. If it is impossible to make all elements equal to 11, return −1-1.

Constraints:

  • 3≤3 \leq nums.length ≤105\leq 10^5

  • 0≤0 \leq nums[i] ≤1\leq 1

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Make Binary Array All Ones I

Minimum Operations to Make Binary Array All Ones I takes a binary array and asks for the fewest flips of three consecutive elements to make every value one, or -1 if impossible.

Statement

You are given a binary array nums.

In one operation, you can choose any 33 consecutive elements from nums and flip each of them, changing every 00 to 11 and every 11 to 00.

Return the minimum number of operations required to make every element in nums equal to 11. If it is impossible to make all elements equal to 11, return −1-1.

Constraints:

  • 3≤3 \leq nums.length ≤105\leq 10^5

  • 0≤0 \leq nums[i] ≤1\leq 1