title: Maximum Number Characters Two Character String
signature: maximum_number_characters_two_character_string <- function(str) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(str, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(str), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          "cI", 
          -1L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          "76478", 
          2L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          "1", 
          -1L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          "tr", 
          -1L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          "10", 
          -1L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          "01", 
          -1L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          "Rmhzp", 
          -1L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          "5784080133917", 
          10L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          "1100", 
          0L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          "OK", 
          -1L
      )))
  
  }
  
  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;
  }