title: Length Longest Sub String Can Make Removed
signature: class Solution {
  
      public int LengthLongestSubStringCanMakeRemoved(string s) {
test_code: using System;
  using System.Numerics;
  using System.Diagnostics;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Security.Cryptography;
  using System.Web.UI;
  using System.Web.Script.Serialization;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  namespace EvaluatePrediction {
      class TestRunner {
          public bool ValidateSolution(int actual, int expected){
              return new JavaScriptSerializer().Serialize(actual) == new JavaScriptSerializer().Serialize(expected);
          }
  
          public string driver(string s, int expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                int pred_result = solution_cls.PLACEHOLDER_FN_NAME(s); 
                if (ValidateSolution(
                      pred_result,
                      expected)){
                  return "PASSED";
                }
                return "FAILED";
              } 
              catch (Exception exception_obj)
              {
                return exception_obj.GetType().FullName;
              }
          }
          static void Main(string[] args) {
              TestRunner runner = new TestRunner();
              String result;
              result = runner.driver(
                  "U", 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  "544", 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  "111", 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  " cDQaNxpRSOe", 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  "42920062459", 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  "00100101", 
                  3
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  "FiC", 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  "302746335230", 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  "1", 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  "ZBLHiwGreUR ", 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
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;
      }