title: Space Optimized Solution Lcs
signature: spaceOptimizedSolutionLcs(x, y) {
test_code: import 'dart:convert';
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  bool validateSolution(int actual, int expected){
      return actual.toString() == expected.toString();
  }
  
  String driver(x, y, int expected){
      try
      {
          if (validateSolution(PLACEHOLDER_FN_NAME(x, y), expected)){
              return "PASSED";
          }
          return "FAILED";
      }catch(exception_object){
          return exception_object.runtimeType.toString();
      }
  }
  
  int main() {
  
      print("TEST-0...${driver(
          "YNpjSv", "qtUkJn", 
          0)
      }");
  
      print("TEST-1...${driver(
          "736519", "07592", 
          2)
      }");
  
      print("TEST-2...${driver(
          "11010000100010", "0", 
          1)
      }");
  
      print("TEST-3...${driver(
          "v ", "qGBQT", 
          0)
      }");
  
      print("TEST-4...${driver(
          "8311172", "157219329531", 
          3)
      }");
  
      print("TEST-5...${driver(
          "100011101011", "1000001111", 
          7)
      }");
  
      print("TEST-6...${driver(
          "u", "YzkubTqLhP", 
          0)
      }");
  
      print("TEST-7...${driver(
          "3943042", "3859", 
          1)
      }");
  
      print("TEST-8...${driver(
          "101", "00010000101010", 
          2)
      }");
  
      print("TEST-9...${driver(
          "MpbfF OsizevaM", "WgsFGaQwtp", 
          2)
      }");
  
      return 0;
  }
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 ];
  }