title: Maximum Number Characters Two Character String
signature: function maximumNumberCharactersTwoCharacterString(str: string): number {
test_code: 
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  function convertToString(value: any): string{
      return JSON.stringify(value, function (key, val) {
          if (val instanceof Set) {
              return Array.from(val);
          } return val;});
  }
  
  function validateSolution(actual: number, expected: number): boolean {
      return convertToString(actual) === convertToString(expected);
  }
  
  function driver(str: string, expected:number): string {
      try{
          if (validateSolution(PLACEHOLDER_FN_NAME(str),expected)){
              return "PASSED";
          }
          return "FAILED";
      } catch (error) {
        return error.name;
      }
      
  }
      
  function main(){
    let result = '';
    result = driver("cI", -1);
    console.log(`TEST-0...${result}`);
  
    result = driver("76478", 2);
    console.log(`TEST-1...${result}`);
  
    result = driver("1", -1);
    console.log(`TEST-2...${result}`);
  
    result = driver("tr", -1);
    console.log(`TEST-3...${result}`);
  
    result = driver("10", -1);
    console.log(`TEST-4...${result}`);
  
    result = driver("01", -1);
    console.log(`TEST-5...${result}`);
  
    result = driver("Rmhzp", -1);
    console.log(`TEST-6...${result}`);
  
    result = driver("5784080133917", 10);
    console.log(`TEST-7...${result}`);
  
    result = driver("1100", 0);
    console.log(`TEST-8...${result}`);
  
    result = driver("OK", -1);
    console.log(`TEST-9...${result}`);
  
  };
  
  main();
source_py: def maximum_number_characters_two_character_string(str):
      n = len(str)
      res = (- 1)
      for i in range(0, (n - 1)):
          for j in range((i + 1), n):
              if (str[i] == str[j]):
                  res = max(res, abs(((j - i) - 1)))
      return res
source_cpp: int maximum_number_characters_two_character_string(string & str) {
    int n = str . length ( );
    int res = - 1;
    for ( int i = 0;
    i < n - 1;
    i ++ ) for ( int j = i + 1;
    j < n;
    j ++ ) if ( str [ i ] == str [ j ] ) res = max ( res, abs ( j - i - 1 ) );
    return res;
  }