title: Count Of Occurrences Of A 101 Pattern In A String
signature: function countOfOccurrencesOfA101PatternInAString(s) {
test_code: 
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function convertToString(value) {
      return JSON.stringify(value, function (key, val) {
          if (val instanceof Set) {
              return Array.from(val);
          } return val;});
  }
  
  function validateSolution(actual, expected){
      return convertToString(actual)===convertToString(expected);
  }
  
  function driver(s, expected){
      try{
          if (validateSolution(PLACEHOLDER_FN_NAME(s),expected)){
              return "PASSED";
          }
          return "FAILED";
      } catch (error) {
        return error.name;
      }
      
  }
      
  function main(){
    let result = '';
    result = driver("1001ab010abc01001", 2);
    console.log(`TEST-0...${result}`);
  
    result = driver("1001010001", 3);
    console.log(`TEST-1...${result}`);
  
    result = driver("010100010100", 3);
    console.log(`TEST-2...${result}`);
  
    result = driver("DLCu", 0);
    console.log(`TEST-3...${result}`);
  
    result = driver("7072430592", 0);
    console.log(`TEST-4...${result}`);
  
    result = driver("011", 0);
    console.log(`TEST-5...${result}`);
  
    result = driver("pnJpypYOza", 0);
    console.log(`TEST-6...${result}`);
  
    result = driver("1037", 0);
    console.log(`TEST-7...${result}`);
  
    result = driver("111", 0);
    console.log(`TEST-8...${result}`);
  
    result = driver("HxK", 0);
    console.log(`TEST-9...${result}`);
  
    process.exit(0);
  };
  
  if (require.main === module) {
    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;
  }