title: Count Of Occurrences Of A 101 Pattern In A String
signature: def count_of_occurrences_of_a_101_pattern_in_a_string(s):
source_py: def count_of_occurrences_of_a_101_pattern_in_a_string(s):
      length = len(s)
      oneSeen = False
      count = 0
      for i in range(length):
          if ((s[i] == '1') and oneSeen):
              if (s[(i - 1)] == '0'):
                  count += 1
          if ((s[i] == '1') and (oneSeen == 0)):
              oneSeen = True
          if ((s[i] != '0') and (s[i] != '1')):
              oneSeen = False
      return count
source_cpp: int count_of_occurrences_of_a_101_pattern_in_a_string(string str) {
    int len = str . size ( );
    bool oneSeen = 0;
    int count = 0;
    for ( int i = 0;
    i < len;
    i ++ ) {
      if ( str [ i ] == '1' && oneSeen == 1 ) if ( str [ i - 1 ] == '0' ) count ++;
      if ( str [ i ] == '1' && oneSeen == 0 ) {
        oneSeen = 1;
        continue;
      }
      if ( str [ i ] != '0' && str [ i ] != '1' ) oneSeen = 0;
    }
    return count;
  }
question_info.test_code: import array
  import bisect
  import collections
  import datetime
  import functools
  import heapq
  import itertools
  import math
  import queue
  import re
  import string
  import sys
  from typing import Any, Dict, List, Optional, Set
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  def validate_solution(actual, expected):
      return actual == expected
  
  def driver(s, expected):
      try:
          if validate_solution(PLACEHOLDER_FN_NAME(
              s),
              expected
          ):
              return "PASSED"
          return "FAILED"
      except Exception as exception_obj:
          return type(exception_obj).__name__
      
  if __name__ == "__main__":
      result = driver("1001ab010abc01001", 2)
      print(f"TEST-0...{result}")
  
      result = driver("1001010001", 3)
      print(f"TEST-1...{result}")
  
      result = driver("010100010100", 3)
      print(f"TEST-2...{result}")
  
      result = driver("DLCu", 0)
      print(f"TEST-3...{result}")
  
      result = driver("7072430592", 0)
      print(f"TEST-4...{result}")
  
      result = driver("011", 0)
      print(f"TEST-5...{result}")
  
      result = driver("pnJpypYOza", 0)
      print(f"TEST-6...{result}")
  
      result = driver("1037", 0)
      print(f"TEST-7...{result}")
  
      result = driver("111", 0)
      print(f"TEST-8...{result}")
  
      result = driver("HxK", 0)
      print(f"TEST-9...{result}")
  
      sys.exit(0)
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.entry_fn_name: count_of_occurrences_of_a_101_pattern_in_a_string
question_info.test_list: [{"idx": 0, "outputs": 2, "inputs": {"s": "1001ab010abc01001"}}, {"idx": 1, "outputs": 3, "inputs": {"s": "1001010001"}}, {"idx": 2, "outputs": 3, "inputs": {"s": "010100010100"}}, {"idx": 3, "outputs": 0, "inputs": {"s": "DLCu"}}, {"idx": 4, "outputs": 0, "inputs": {"s": "7072430592"}}, {"idx": 5, "outputs": 0, "inputs": {"s": "011"}}, {"idx": 6, "outputs": 0, "inputs": {"s": "pnJpypYOza"}}, {"idx": 7, "outputs": 0, "inputs": {"s": "1037"}}, {"idx": 8, "outputs": 0, "inputs": {"s": "111"}}, {"idx": 9, "outputs": 0, "inputs": {"s": "HxK"}}]
question_info.entry_cls_name: Solution