title: Maximum Number Characters Two Character String
signature: func maximumNumberCharactersTwoCharacterString(str string) int {
test_code: package main
  
  import (
      "fmt"
      "reflect"
      "math"
      "sort"
  )
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  func validateSolution(actual int, expected int) bool {
      return reflect.DeepEqual(actual,expected)
  }
  
  func driver(str string, expected int) string {
      if validateSolution(PLACEHOLDER_FN_NAME(str),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver("cI", -1)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver("76478", 2)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver("1", -1)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver("tr", -1)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver("10", -1)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver("01", -1)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver("Rmhzp", -1)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver("5784080133917", 10)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver("1100", 0)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver("OK", -1)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
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;
  }