title: Count Substrings With Same First And Last Characters
signature: func countSubstringsWithSameFirstAndLastCharacters(s 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(s string, expected int) string {
      if validateSolution(PLACEHOLDER_FN_NAME(s),expected) {
              return "PASSED"
      }
      return "FAILED"
  
  }
  
  func main() {
  
      // Use imports to avoid undefined errors
      var _ = reflect.DeepEqual
      _ = math.Abs
      _ = sort.Sort
      result := ""
      result = driver("LZIKA", 5)
      fmt.Printf("TEST-0...%s\n", result)
      
      result = driver("0556979952", 16)
      fmt.Printf("TEST-1...%s\n", result)
      
      result = driver("110010", 12)
      fmt.Printf("TEST-2...%s\n", result)
      
      result = driver("kGaYfd", 6)
      fmt.Printf("TEST-3...%s\n", result)
      
      result = driver("413567670657", 19)
      fmt.Printf("TEST-4...%s\n", result)
      
      result = driver("01001", 9)
      fmt.Printf("TEST-5...%s\n", result)
      
      result = driver("EQPuFa", 6)
      fmt.Printf("TEST-6...%s\n", result)
      
      result = driver("48848378", 15)
      fmt.Printf("TEST-7...%s\n", result)
      
      result = driver("110", 4)
      fmt.Printf("TEST-8...%s\n", result)
      
      result = driver("PLehNeP", 9)
      fmt.Printf("TEST-9...%s\n", result)
      
          
  }
source_py: def count_substrings_with_same_first_and_last_characters(s):
      result = 0
      n = len(s)
      for i in range(n):
          for j in range(i, n):
              if (s[i] == s[j]):
                  result = (result + 1)
      return result
source_cpp: int count_substrings_with_same_first_and_last_characters(string s) {
    int result = 0;
    int n = s . length ( );
    for ( int i = 0;
    i < n;
    i ++ ) for ( int j = i;
    j < n;
    j ++ ) if ( s [ i ] == s [ j ] ) result ++;
    return result;
  }