title: Number Subsequences Ab String Repeated K Times
signature: class Solution {
  
      public Float numberSubsequencesAbStringRepeatedKTimes(String s, Integer k) {
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.extension: java
question_info.entry_fn_name: numberSubsequencesAbStringRepeatedKTimes
question_info.entry_cls_name: Solution
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.test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(String s, Integer k, Float expected){
          try{
              Driver driver = new Driver();
              if (driver.run(s, k,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution("abbc", 96, 9312.0f);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution("abahk", 7, 49.0f);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution("hugbabab", 5, 75.0f);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution("abadbc", 60, 7260.0f);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution("nkg9", 8, 0.0f);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution("jh7dab", 41, 861.0f);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution("abd", 87, 3828.0f);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution("aabb8yk", 4, 40.0f);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution("1111", 18, 0.0f);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution("PFXAhr", 8, 0.0f);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(String s, Integer k, Float expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(s, k),expected);
      }
      
      public boolean validateSolution(Float actual, Float expected){
          return Math.abs(actual - expected) < 1e-06f;
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: java __FILENAME__