title: Count Distinct Occurrences As A Subsequence
signature: fun countDistinctOccurrencesAsASubsequence(s: String, t: String): Int {
source_py: def count_distinct_occurrences_as_a_subsequence(S, T):
      m = len(T)
      n = len(S)
      if (m > n):
          return 0
      mat = [[0 for _ in range((n + 1))] for __ in range((m + 1))]
      for i in range(1, (m + 1)):
          mat[i][0] = 0
      for j in range((n + 1)):
          mat[0][j] = 1
      for i in range(1, (m + 1)):
          for j in range(1, (n + 1)):
              if (T[(i - 1)] != S[(j - 1)]):
                  mat[i][j] = mat[i][(j - 1)]
              else:
                  mat[i][j] = (mat[i][(j - 1)] + mat[(i - 1)][(j - 1)])
      return mat[m][n]
source_cpp: int count_distinct_occurrences_as_a_subsequence(string S, string T) {
    int m = T . length ( ), n = S . length ( );
    if ( m > n ) return 0;
    int mat [ m + 1 ] [ n + 1 ];
    for ( int i = 1;
    i <= m;
    i ++ ) mat [ i ] [ 0 ] = 0;
    for ( int j = 0;
    j <= n;
    j ++ ) mat [ 0 ] [ j ] = 1;
    for ( int i = 1;
    i <= m;
    i ++ ) {
      for ( int j = 1;
      j <= n;
      j ++ ) {
        if ( T [ i - 1 ] != S [ j - 1 ] ) mat [ i ] [ j ] = mat [ i ] [ j - 1 ];
        else mat [ i ] [ j ] = mat [ i ] [ j - 1 ] + mat [ i - 1 ] [ j - 1 ];
      }
    }
    return mat [ m ] [ n ];
  }
question_info.test_list: [{"idx": 0, "outputs": 3, "inputs": {"s": "banana", "t": "ban"}}, {"idx": 1, "outputs": 2, "inputs": {"s": "49597223", "t": "42"}}, {"idx": 2, "outputs": 20, "inputs": {"s": "1000010000011", "t": "010"}}, {"idx": 3, "outputs": 0, "inputs": {"s": "BTlzufK", "t": "EpsVuzP lf"}}, {"idx": 4, "outputs": 2, "inputs": {"s": "3474007", "t": "370"}}, {"idx": 5, "outputs": 0, "inputs": {"s": "0010", "t": "00000"}}, {"idx": 6, "outputs": 1, "inputs": {"s": "dKHhoTD", "t": "doT"}}, {"idx": 7, "outputs": 4, "inputs": {"s": "9123259723", "t": "123"}}, {"idx": 8, "outputs": 6, "inputs": {"s": "11001000111110", "t": "0"}}, {"idx": 9, "outputs": 1, "inputs": {"s": "iY WJlIZ", "t": "iI"}}]
question_info.extension: kts
question_info.test_code: package main
  
  import kotlin.text.*
  import kotlin.math.*
  
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  fun validateSolution(actual:Int, expected:Int):Boolean{
    return actual.equals(expected)
  }
  fun driver(s: String, t: String, expected:Int):String {
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME(s, t), expected)) {
                return "PASSED"
        }
        return "FAILED"
      } catch (e: Exception){
        return e::class.simpleName as String
      }
  
  }
  
  fun main() {
      var result: String = ""
      result = driver("banana", "ban", 3)
      println("TEST-0...${result}")
      
      result = driver("49597223", "42", 2)
      println("TEST-1...${result}")
      
      result = driver("1000010000011", "010", 20)
      println("TEST-2...${result}")
      
      result = driver("BTlzufK", "EpsVuzP lf", 0)
      println("TEST-3...${result}")
      
      result = driver("3474007", "370", 2)
      println("TEST-4...${result}")
      
      result = driver("0010", "00000", 0)
      println("TEST-5...${result}")
      
      result = driver("dKHhoTD", "doT", 1)
      println("TEST-6...${result}")
      
      result = driver("9123259723", "123", 4)
      println("TEST-7...${result}")
      
      result = driver("11001000111110", "0", 6)
      println("TEST-8...${result}")
      
      result = driver("iY WJlIZ", "iI", 1)
      println("TEST-9...${result}")
      
          
  }
  
  main()
question_info.entry_fn_name: countDistinctOccurrencesAsASubsequence
question_info.entry_cls_name: Solution
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: kotlinc -script __FILENAME__ -no-reflect -nowarn