title: Number Subsequences Ab String Repeated K Times
signature: def numberSubsequencesAbStringRepeatedKTimes(s: String, k: Int) = {
test_code: import scala.collection.mutable.HashMap
  import scala.collection.immutable.HashSet
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  
  // TESTING CODE 
  // ============================================
  def validateSolution(actual: Float , expected: Float): Boolean = {
      (actual - expected).abs < 1e-06F
  }
  
  def driver(s: String, k: Int, expected: Float): String = {
      try {
          if (validateSolution(PLACEHOLDER_FN_NAME(s, k),expected)) {
              "PASSED"
          } else{
              "FAILED"
          }
      }catch{
          case e: Exception => {e.getClass.getName}
      }
  
  }
  object QuestionEvaluator extends App {
  
      println(s"TEST-0...${driver(
        "abbc", 96, 
        9312.0F    
      )}")   
  
  
      println(s"TEST-1...${driver(
        "abahk", 7, 
        49.0F    
      )}")   
  
  
      println(s"TEST-2...${driver(
        "hugbabab", 5, 
        75.0F    
      )}")   
  
  
      println(s"TEST-3...${driver(
        "abadbc", 60, 
        7260.0F    
      )}")   
  
  
      println(s"TEST-4...${driver(
        "nkg9", 8, 
        0.0F    
      )}")   
  
  
      println(s"TEST-5...${driver(
        "jh7dab", 41, 
        861.0F    
      )}")   
  
  
      println(s"TEST-6...${driver(
        "abd", 87, 
        3828.0F    
      )}")   
  
  
      println(s"TEST-7...${driver(
        "aabb8yk", 4, 
        40.0F    
      )}")   
  
  
      println(s"TEST-8...${driver(
        "1111", 18, 
        0.0F    
      )}")   
  
  
      println(s"TEST-9...${driver(
        "PFXAhr", 8, 
        0.0F    
      )}")   
  
  }
  
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;
  }