title: Count Of Occurrences Of A 101 Pattern In A String
signature: count_of_occurrences_of_a_101_pattern_in_a_string <- function(s) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(s, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(s), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          "1001ab010abc01001", 
          2L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          "1001010001", 
          3L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          "010100010100", 
          3L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          "DLCu", 
          0L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          "7072430592", 
          0L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          "011", 
          0L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          "pnJpypYOza", 
          0L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          "1037", 
          0L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          "111", 
          0L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          "HxK", 
          0L
      )))
  
  }
  
  main()
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;
  }