title: Count Substrings With Same First And Last Characters
signature: function countSubstringsWithSameFirstAndLastCharacters(s: string): number {
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;
  }
question_info.test_list: [{"idx": 0, "outputs": 5, "inputs": {"s": "LZIKA"}}, {"idx": 1, "outputs": 16, "inputs": {"s": "0556979952"}}, {"idx": 2, "outputs": 12, "inputs": {"s": "110010"}}, {"idx": 3, "outputs": 6, "inputs": {"s": "kGaYfd"}}, {"idx": 4, "outputs": 19, "inputs": {"s": "413567670657"}}, {"idx": 5, "outputs": 9, "inputs": {"s": "01001"}}, {"idx": 6, "outputs": 6, "inputs": {"s": "EQPuFa"}}, {"idx": 7, "outputs": 15, "inputs": {"s": "48848378"}}, {"idx": 8, "outputs": 4, "inputs": {"s": "110"}}, {"idx": 9, "outputs": 9, "inputs": {"s": "PLehNeP"}}]
question_info.entry_cls_name: Solution
question_info.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(s: string, expected:number): string {
      try{
          if (validateSolution(PLACEHOLDER_FN_NAME(s),expected)){
              return "PASSED";
          }
          return "FAILED";
      } catch (error) {
        return error.name;
      }
      
  }
      
  function main(){
    let result = '';
    result = driver("LZIKA", 5);
    console.log(`TEST-0...${result}`);
  
    result = driver("0556979952", 16);
    console.log(`TEST-1...${result}`);
  
    result = driver("110010", 12);
    console.log(`TEST-2...${result}`);
  
    result = driver("kGaYfd", 6);
    console.log(`TEST-3...${result}`);
  
    result = driver("413567670657", 19);
    console.log(`TEST-4...${result}`);
  
    result = driver("01001", 9);
    console.log(`TEST-5...${result}`);
  
    result = driver("EQPuFa", 6);
    console.log(`TEST-6...${result}`);
  
    result = driver("48848378", 15);
    console.log(`TEST-7...${result}`);
  
    result = driver("110", 4);
    console.log(`TEST-8...${result}`);
  
    result = driver("PLehNeP", 9);
    console.log(`TEST-9...${result}`);
  
  };
  
  main();
question_info.extension: ts
question_info.entry_fn_name: countSubstringsWithSameFirstAndLastCharacters
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: tsc --target es2020 --lib es5,dom,es2015,es2020 __FILENAME__
question_info.commands: node __FILENAME__.js