title: Count Substrings With Same First And Last Characters
signature: def countSubstringsWithSameFirstAndLastCharacters(s: String) = {
test_code: import scala.collection.mutable.HashMap
  import scala.collection.immutable.HashSet
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  
  // TESTING CODE 
  // ============================================
  def validateSolution(actual: Int , expected: Int): Boolean = {
      actual.toString == expected.toString
  }
  
  def driver(s: String, expected: Int): String = {
      try {
          if (validateSolution(PLACEHOLDER_FN_NAME(s),expected)) {
              "PASSED"
          } else{
              "FAILED"
          }
      }catch{
          case e: Exception => {e.getClass.getName}
      }
  
  }
  object QuestionEvaluator extends App {
  
      println(s"TEST-0...${driver(
        "LZIKA", 
        5    
      )}")   
  
  
      println(s"TEST-1...${driver(
        "0556979952", 
        16    
      )}")   
  
  
      println(s"TEST-2...${driver(
        "110010", 
        12    
      )}")   
  
  
      println(s"TEST-3...${driver(
        "kGaYfd", 
        6    
      )}")   
  
  
      println(s"TEST-4...${driver(
        "413567670657", 
        19    
      )}")   
  
  
      println(s"TEST-5...${driver(
        "01001", 
        9    
      )}")   
  
  
      println(s"TEST-6...${driver(
        "EQPuFa", 
        6    
      )}")   
  
  
      println(s"TEST-7...${driver(
        "48848378", 
        15    
      )}")   
  
  
      println(s"TEST-8...${driver(
        "110", 
        4    
      )}")   
  
  
      println(s"TEST-9...${driver(
        "PLehNeP", 
        9    
      )}")   
  
  }
  
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;
  }