title: Space Optimized Solution Lcs
signature: function spaceOptimizedSolutionLcs(x: string, y: string): number {
source_py: def space_optimized_solution_lcs(X, Y):
      m = len(X)
      n = len(Y)
      L = [[0 for i in range((n + 1))] for j in range(2)]
      bi = bool
      for i in range(m):
          bi = (i & 1)
          for j in range((n + 1)):
              if ((i == 0) or (j == 0)):
                  L[bi][j] = 0
              elif (X[i] == Y[(j - 1)]):
                  L[bi][j] = (L[(1 - bi)][(j - 1)] + 1)
              else:
                  L[bi][j] = max(L[(1 - bi)][j], L[bi][(j - 1)])
      return L[bi][n]
source_cpp: int space_optimized_solution_lcs(string & X, string & Y) {
    int m = X . length ( ), n = Y . length ( );
    int L [ 2 ] [ n + 1 ];
    bool bi;
    for ( int i = 0;
    i <= m;
    i ++ ) {
      bi = i & 1;
      for ( int j = 0;
      j <= n;
      j ++ ) {
        if ( i == 0 || j == 0 ) L [ bi ] [ j ] = 0;
        else if ( X [ i - 1 ] == Y [ j - 1 ] ) L [ bi ] [ j ] = L [ 1 - bi ] [ j - 1 ] + 1;
        else L [ bi ] [ j ] = max ( L [ 1 - bi ] [ j ], L [ bi ] [ j - 1 ] );
      }
    }
    return L [ bi ] [ n ];
  }
question_info.test_list: [{"idx": 0, "outputs": 0, "inputs": {"x": "YNpjSv", "y": "qtUkJn"}}, {"idx": 1, "outputs": 2, "inputs": {"x": "736519", "y": "07592"}}, {"idx": 2, "outputs": 1, "inputs": {"x": "11010000100010", "y": "0"}}, {"idx": 3, "outputs": 0, "inputs": {"x": "v ", "y": "qGBQT"}}, {"idx": 4, "outputs": 3, "inputs": {"x": "8311172", "y": "157219329531"}}, {"idx": 5, "outputs": 7, "inputs": {"x": "100011101011", "y": "1000001111"}}, {"idx": 6, "outputs": 0, "inputs": {"x": "u", "y": "YzkubTqLhP"}}, {"idx": 7, "outputs": 1, "inputs": {"x": "3943042", "y": "3859"}}, {"idx": 8, "outputs": 2, "inputs": {"x": "101", "y": "00010000101010"}}, {"idx": 9, "outputs": 2, "inputs": {"x": "MpbfF OsizevaM", "y": "WgsFGaQwtp"}}]
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(x: string, y: string, expected:number): string {
      try{
          if (validateSolution(PLACEHOLDER_FN_NAME(x, y),expected)){
              return "PASSED";
          }
          return "FAILED";
      } catch (error) {
        return error.name;
      }
      
  }
      
  function main(){
    let result = '';
    result = driver("YNpjSv", "qtUkJn", 0);
    console.log(`TEST-0...${result}`);
  
    result = driver("736519", "07592", 2);
    console.log(`TEST-1...${result}`);
  
    result = driver("11010000100010", "0", 1);
    console.log(`TEST-2...${result}`);
  
    result = driver("v ", "qGBQT", 0);
    console.log(`TEST-3...${result}`);
  
    result = driver("8311172", "157219329531", 3);
    console.log(`TEST-4...${result}`);
  
    result = driver("100011101011", "1000001111", 7);
    console.log(`TEST-5...${result}`);
  
    result = driver("u", "YzkubTqLhP", 0);
    console.log(`TEST-6...${result}`);
  
    result = driver("3943042", "3859", 1);
    console.log(`TEST-7...${result}`);
  
    result = driver("101", "00010000101010", 2);
    console.log(`TEST-8...${result}`);
  
    result = driver("MpbfF OsizevaM", "WgsFGaQwtp", 2);
    console.log(`TEST-9...${result}`);
  
  };
  
  main();
question_info.extension: ts
question_info.entry_fn_name: spaceOptimizedSolutionLcs
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