Problem statement

https://binarysearch.com/problems/Flip-to-Zeros/

Solution

It all depends on number of groups of adjacent 0/1 we have and we subract 1 if first group is zeroes.

Complexity

Time complexity is O(n), space is O(1)

Code

class Solution:
    def solve(self, nums):
        ans = 0
        for x, y in groupby(nums):
            ans += 1
        if nums and nums[0] == 0: ans -= 1
        return ans