title: Length Longest Sub String Can Make Removed
signature: int lengthLongestSubStringCanMakeRemoved(string s) {
test_code: #include <algorithm>
  #include <assert.h>
  #include <cstdlib>
  #include <iostream>
  #include <map>
  #include <set>
  #include <string>
  #include <tuple> 
  #include <unordered_map>
  #include <vector>
  #include <math.h>
  #include <cmath>
  #include <bits/stdc++.h>
  #include <numeric>
  #include <functional>
  
  using namespace std;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(int actual, int expected){
      return actual == expected;
  }
  
  string driver(string s, int expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(s), expected)){
              return "PASSED";
          }
          return "FAILED";
      }
      catch (const std::overflow_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::runtime_error& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (const std::exception& exception_obj)
      {
          return typeid(exception_obj).name();
      }
      catch (...)
      {
          return "UNK_ERROR";
      }
  }
  
  int main() {
      string result = "";
  
      result = driver("U", 0); 
      cout << "TEST-" << 0 << "..."
           <<  result
           << "\n";
  
      result = driver("544", 0); 
      cout << "TEST-" << 1 << "..."
           <<  result
           << "\n";
  
      result = driver("111", 0); 
      cout << "TEST-" << 2 << "..."
           <<  result
           << "\n";
  
      result = driver(" cDQaNxpRSOe", 0); 
      cout << "TEST-" << 3 << "..."
           <<  result
           << "\n";
  
      result = driver("42920062459", 0); 
      cout << "TEST-" << 4 << "..."
           <<  result
           << "\n";
  
      result = driver("00100101", 3); 
      cout << "TEST-" << 5 << "..."
           <<  result
           << "\n";
  
      result = driver("FiC", 0); 
      cout << "TEST-" << 6 << "..."
           <<  result
           << "\n";
  
      result = driver("302746335230", 0); 
      cout << "TEST-" << 7 << "..."
           <<  result
           << "\n";
  
      result = driver("1", 0); 
      cout << "TEST-" << 8 << "..."
           <<  result
           << "\n";
  
      result = driver("ZBLHiwGreUR ", 0); 
      cout << "TEST-" << 9 << "..."
           <<  result
           << "\n";
  
      return 0;
  }
source_py: def length_longest_sub_string_can_make_removed(S):
      arr = []
      arr.append(['@', (- 1)])
      maxlen = 0
      for i in range(len(S)):
          arr.append([S[i], i])
          while ((len(arr) >= 3) and (arr[(len(arr) - 3)][0] == '1') and (arr[(len(arr) - 2)][0] == '0') and (arr[(len(arr) - 1)][0] == '0')):
              arr.pop()
              arr.pop()
              arr.pop()
          tmp = arr[(- 1)]
          maxlen = max(maxlen, (i - tmp[1]))
      return maxlen
source_cpp: int length_longest_sub_string_can_make_removed(string str) {
    vector < pair < char, int > > arr;
    arr . push_back ( {
      '@', - 1 }
      );
      int maxlen = 0;
      for ( int i = 0;
      i < str . length ( );
      ++ i ) {
        arr . push_back ( {
          str [ i ], i }
          );
          while ( arr . size ( ) >= 3 && arr [ arr . size ( ) - 3 ] . first == '1' && arr [ arr . size ( ) - 2 ] . first == '0' && arr [ arr . size ( ) - 1 ] . first == '0' ) {
            arr . pop_back ( );
            arr . pop_back ( );
            arr . pop_back ( );
          }
          int tmp = arr . back ( ) . second;
          maxlen = max ( maxlen, i - tmp );
        }
        return maxlen;
      }