title: Space Optimized Solution Lcs
signature: pub fn space_optimized_solution_lcs(x: String, y: String) -> i32 {
test_code: use std::collections::HashMap;
  use std::collections::HashSet;
  use std::cmp::*;
  use std::collections::*;
  use std::fmt::*; 
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  pub fn validate_solution(actual: i32, expected: i32)->bool{
  return actual==expected
  }
  pub fn driver(x: String, y: String, expected: i32)->String{
      if validate_solution(PLACEHOLDER_FN_NAME(x, y), expected) {
        return "PASSED".to_string();
      };
      return "FAILED".to_string();
  
  }
  
  fn main() {
      println!("TEST-0...{}", driver(
        "YNpjSv".to_string(), "qtUkJn".to_string(), 
        0
      ));
      
      println!("TEST-1...{}", driver(
        "736519".to_string(), "07592".to_string(), 
        2
      ));
      
      println!("TEST-2...{}", driver(
        "11010000100010".to_string(), "0".to_string(), 
        1
      ));
      
      println!("TEST-3...{}", driver(
        "v ".to_string(), "qGBQT".to_string(), 
        0
      ));
      
      println!("TEST-4...{}", driver(
        "8311172".to_string(), "157219329531".to_string(), 
        3
      ));
      
      println!("TEST-5...{}", driver(
        "100011101011".to_string(), "1000001111".to_string(), 
        7
      ));
      
      println!("TEST-6...{}", driver(
        "u".to_string(), "YzkubTqLhP".to_string(), 
        0
      ));
      
      println!("TEST-7...{}", driver(
        "3943042".to_string(), "3859".to_string(), 
        1
      ));
      
      println!("TEST-8...{}", driver(
        "101".to_string(), "00010000101010".to_string(), 
        2
      ));
      
      println!("TEST-9...{}", driver(
        "MpbfF OsizevaM".to_string(), "WgsFGaQwtp".to_string(), 
        2
      ));
      
  }
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 ];
  }