title: Minimum number of Alternating 1 and 0
body: <p>I want to find the minimum number of flips required to get an alternating of [0, 1, 0, 1] for example given [1, 1, 0, 1]. so in this case, it is one flip.</p>
  
  <pre><code>def solution(A):
      count = 0
      myDict = {}
      myDict[1] = True
      myDict[0] = False
  
      next = None
      # first element value
      val = myDict[A[0]]
      if val == True:
          next = False
      else:
          next = True
  
      for element in A[1:]:
          if next != myDict[element]:
              count += 1
              # do something to update element
              myDict[element] = next
          if myDict[element] == True:
              next = False
          else:
              next = True
  
      return count
  </code></pre>
  
  <p>My solution does not work for the input [1, 1, 0, 1, 1]. Because it gives back 3 when the answer it should give back is 2(change the first index and last index elements to 0). How can i solve this? </p>