input: from typing import List
  
  def min_flips_to_all_ones(nums: List[int]) -> int:
      """
      Given a binary array nums.
  
      You can perform the following operation on the array any number of times (including zero):
  
      Pick any 3 consecutive elements from the array and flip their values.
      Flipping an element means changing its value from 0 to 1 or from 1 to 0.
  
      Return the smallest number of operations needed to convert all elements in nums to 1. If it cannot be done, return -1.
  
      Examples:
      >>> nums = [0,1,1,1,0,0]
      3
      >>> nums = [0,1,1,1]
      -1
  
      Constraints:
      3 <= len(nums) <= 10^5
      0 <= nums[i] <= 1
      """
output:     
      n = len(nums)
      
      if n < 3:
          return -1 if 0 in nums else 0
  
      flip_count = 0
  
      for i in range(n - 2):
          # If the current element is 0, flip the triplet starting from the current element
          if nums[i] == 0:
              nums[i] = 1
              nums[i + 1] = 1 - nums[i + 1]
              nums[i + 2] = 1 - nums[i + 2]
              flip_count += 1
  
      # After processing check if all elements are 1
      for i in range(n):
          if nums[i] == 0:
              return -1
  
      return flip_count
  