title: Number Subsequences Ab String Repeated K Times
signature: function numberSubsequencesAbStringRepeatedKTimes(s: string, k: number): number {
source_py: def number_subsequences_ab_string_repeated_k_times(s, K):
      n = len(s)
      c1 = 0
      c2 = 0
      C = 0
      for i in range(n):
          if (s[i] == 'a'):
              c1 += 1
          if (s[i] == 'b'):
              c2 += 1
              C += c1
      return ((C * K) + ((((K * (K - 1)) / 2) * c1) * c2))
source_cpp: int number_subsequences_ab_string_repeated_k_times(string s, int K) {
    int n = s . length ( );
    int C, c1 = 0, c2 = 0;
    for ( int i = 0;
    i < n;
    i ++ ) {
      if ( s [ i ] == 'a' ) c1 ++;
      if ( s [ i ] == 'b' ) {
        c2 ++;
        C += c1;
      }
    }
    return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2;
  }
question_info.test_list: [{"idx": 0, "outputs": 9312.0, "inputs": {"s": "abbc", "k": 96}}, {"idx": 1, "outputs": 49.0, "inputs": {"s": "abahk", "k": 7}}, {"idx": 2, "outputs": 75.0, "inputs": {"s": "hugbabab", "k": 5}}, {"idx": 3, "outputs": 7260.0, "inputs": {"s": "abadbc", "k": 60}}, {"idx": 4, "outputs": 0.0, "inputs": {"s": "nkg9", "k": 8}}, {"idx": 5, "outputs": 861.0, "inputs": {"s": "jh7dab", "k": 41}}, {"idx": 6, "outputs": 3828.0, "inputs": {"s": "abd", "k": 87}}, {"idx": 7, "outputs": 40.0, "inputs": {"s": "aabb8yk", "k": 4}}, {"idx": 8, "outputs": 0.0, "inputs": {"s": "1111", "k": 18}}, {"idx": 9, "outputs": 0.0, "inputs": {"s": "PFXAhr", "k": 8}}]
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 Math.abs(actual - expected) < 1e-06;
  }
  
  function driver(s: string, k: number, expected:number): string {
      try{
          if (validateSolution(PLACEHOLDER_FN_NAME(s, k),expected)){
              return "PASSED";
          }
          return "FAILED";
      } catch (error) {
        return error.name;
      }
      
  }
      
  function main(){
    let result = '';
    result = driver("abbc", 96, 9312.0);
    console.log(`TEST-0...${result}`);
  
    result = driver("abahk", 7, 49.0);
    console.log(`TEST-1...${result}`);
  
    result = driver("hugbabab", 5, 75.0);
    console.log(`TEST-2...${result}`);
  
    result = driver("abadbc", 60, 7260.0);
    console.log(`TEST-3...${result}`);
  
    result = driver("nkg9", 8, 0.0);
    console.log(`TEST-4...${result}`);
  
    result = driver("jh7dab", 41, 861.0);
    console.log(`TEST-5...${result}`);
  
    result = driver("abd", 87, 3828.0);
    console.log(`TEST-6...${result}`);
  
    result = driver("aabb8yk", 4, 40.0);
    console.log(`TEST-7...${result}`);
  
    result = driver("1111", 18, 0.0);
    console.log(`TEST-8...${result}`);
  
    result = driver("PFXAhr", 8, 0.0);
    console.log(`TEST-9...${result}`);
  
  };
  
  main();
question_info.extension: ts
question_info.entry_fn_name: numberSubsequencesAbStringRepeatedKTimes
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