title: Count Of Occurrences Of A 101 Pattern In A String
signature: class Solution {
  
      public Integer countOfOccurrencesOfA101PatternInAString(String s) {
test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(String s, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(s,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution("1001ab010abc01001", 2);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution("1001010001", 3);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution("010100010100", 3);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution("DLCu", 0);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution("7072430592", 0);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution("011", 0);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution("pnJpypYOza", 0);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution("1037", 0);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution("111", 0);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution("HxK", 0);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(String s, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(s),expected);
      }
      
      public boolean validateSolution(Integer actual, Integer expected){
          return actual.equals(expected);
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
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;
  }