title: Longest Common Increasing Subsequence Lcs Lis
signature: longest_common_increasing_subsequence_lcs_lis <- function(arr1, n, arr2, m) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr1, n, arr2, m, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr1, n, arr2, m), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(1L, 7L, 9L, 35L, 43L, 51L, 51L, 66L, 88L), 5L, list(10L, 21L, 38L, 50L, 65L, 67L, 87L, 93L, 99L), 8L, 
          0L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-52L, 52L, -92L, -46L, -94L, 30L, -36L, 18L, -98L, 22L, -36L, 96L, -88L, -50L, 50L), 7L, list(-58L, 40L, 56L, -62L, -92L, -94L, 40L, 18L, -2L, -76L, -78L, -14L, 44L, 84L, 4L), 10L, 
          1L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 36L, list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 22L, 
          2L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(5L, 74L, 29L), 1L, list(57L, 33L, 48L), 1L, 
          0L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-84L, -74L, -70L, -62L, -56L, -56L, -52L, -2L, 6L, 24L, 28L, 44L, 44L, 52L), 8L, list(-98L, -96L, -88L, -66L, -32L, -26L, -24L, -20L, -4L, 20L, 48L, 74L, 90L, 96L), 12L, 
          0L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 1L, 0L), 17L, list(1L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L), 15L, 
          2L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(3L, 4L, 4L, 7L, 15L, 15L, 16L, 22L, 32L, 32L, 37L, 39L, 39L, 41L, 43L, 46L, 47L, 47L, 49L, 75L, 79L, 80L, 86L, 88L, 93L), 19L, list(9L, 12L, 15L, 20L, 22L, 27L, 28L, 28L, 30L, 31L, 35L, 39L, 47L, 58L, 58L, 60L, 73L, 74L, 76L, 78L, 80L, 86L, 95L, 96L, 98L), 14L, 
          4L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(70L, -64L, 0L, 52L, 32L, -98L, 38L, -8L, 34L, 70L, 98L, 58L, -48L, -60L, -28L, -22L, -72L, 82L, -98L, -36L), 16L, list(-18L, 88L, -40L, -52L, 30L, -10L, -18L, -56L, 84L, -22L, -64L, 80L, -14L, -64L, 40L, 92L, 48L, -8L, 24L, 82L), 12L, 
          1L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L), 7L, list(0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 7L, 
          2L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(46L, 87L, 98L), 2L, list(67L, 31L, 54L), 2L, 
          0L
      )))
  
  }
  
  main()
source_py: def longest_common_increasing_subsequence_lcs_lis(arr1, n, arr2, m):
      table = ([0] * m)
      for j in range(m):
          table[j] = 0
      for i in range(n):
          current = 0
          for j in range(m):
              if (arr1[i] == arr2[j]):
                  if ((current + 1) > table[j]):
                      table[j] = (current + 1)
              if (arr1[i] > arr2[j]):
                  if (table[j] > current):
                      current = table[j]
      result = 0
      for i in range(m):
          if (table[i] > result):
              result = table[i]
      return result
source_cpp: int longest_common_increasing_subsequence_lcs_lis(vector<int> arr1, int n, vector<int> arr2, int m) {
    int table [ m ];
    for ( int j = 0;
    j < m;
    j ++ ) table [ j ] = 0;
    for ( int i = 0;
    i < n;
    i ++ ) {
      int current = 0;
      for ( int j = 0;
      j < m;
      j ++ ) {
        if ( arr1 [ i ] == arr2 [ j ] ) if ( current + 1 > table [ j ] ) table [ j ] = current + 1;
        if ( arr1 [ i ] > arr2 [ j ] ) if ( table [ j ] > current ) current = table [ j ];
      }
    }
    int result = 0;
    for ( int i = 0;
    i < m;
    i ++ ) if ( table [ i ] > result ) result = table [ i ];
    return result;
  }