title: Longest Increasing Odd Even Subsequence
signature: function longest_increasing_odd_even_subsequence(arr, n)
source_py: def longest_increasing_odd_even_subsequence(arr, n):
      lioes = list()
      maxLen = 0
      for i in range(n):
          lioes.append(1)
      i = 1
      for i in range(n):
          for j in range(i):
              if ((arr[i] > arr[j]) and (((arr[i] + arr[j]) % 2) != 0) and (lioes[i] < (lioes[j] + 1))):
                  lioes[i] = (lioes[j] + 1)
      for i in range(n):
          if (maxLen < lioes[i]):
              maxLen = lioes[i]
      return maxLen
source_cpp: int longest_increasing_odd_even_subsequence(vector<int> arr, int n) {
    int lioes [ n ];
    int maxLen = 0;
    for ( int i = 0;
    i < n;
    i ++ ) lioes [ i ] = 1;
    for ( int i = 1;
    i < n;
    i ++ ) for ( int j = 0;
    j < i;
    j ++ ) if ( arr [ i ] > arr [ j ] && ( arr [ i ] + arr [ j ] ) % 2 != 0 && lioes [ i ] < lioes [ j ] + 1 ) lioes [ i ] = lioes [ j ] + 1;
    for ( int i = 0;
    i < n;
    i ++ ) if ( maxLen < lioes [ i ] ) maxLen = lioes [ i ];
    return maxLen;
  }
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(arr, n, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(arr, n) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver({7, 8, 9, 16, 16, 27, 32, 33, 35, 35, 39, 39, 41, 42, 44, 47, 48, 50, 56, 59, 66, 69, 70, 73, 74, 76, 78, 87, 87, 89, 94, 96, 96, 98, 98}, 32, 18)
      print(string.format("TEST-0...%s",result))
  
      result = driver({40, 76, -54, -92, -28, -96, 8, 60, 28, -38, -62, -40, -16, 16, 52, 28, 70, -56, -50, 46, 68, -16, -56, 46, 42, 70, 52, -34, 86, -32, -50, 64, 36, 54, 20, 82, 84}, 25, 1)
      print(string.format("TEST-1...%s",result))
  
      result = driver({0, 0, 0, 0, 1, 1, 1}, 4, 1)
      print(string.format("TEST-2...%s",result))
  
      result = driver({15, 19, 87, 44, 15, 48, 21, 85, 90, 30, 88, 95, 48, 92, 29, 52, 46, 46, 7, 23, 96, 97, 43}, 19, 5)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-98, -96, -94, -94, -94, -80, -80, -78, -64, -62, -62, -46, -42, -38, -36, -36, -34, -32, -20, -18, -16, -12, -8, -4, -4, -2, -2, 2, 6, 12, 34, 40, 42, 44, 46, 46, 50, 54, 58, 58, 70, 72, 72, 76, 78, 86}, 33, 1)
      print(string.format("TEST-4...%s",result))
  
      result = driver({0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1}, 13, 2)
      print(string.format("TEST-5...%s",result))
  
      result = driver({6, 7, 19, 36, 44, 63, 68, 72, 83}, 8, 5)
      print(string.format("TEST-6...%s",result))
  
      result = driver({-64, 12, 56, 50, 94, 6, 0, 70, -70, 46, -84, -64, 4, 76, 28, 94, -8, 24, 76, 64, -62, -34}, 15, 1)
      print(string.format("TEST-7...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 21, 2)
      print(string.format("TEST-8...%s",result))
  
      result = driver({71, 57, 20, 8, 90, 69, 15, 62, 45, 14, 65, 20, 48, 9}, 10, 3)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 18, "inputs": {"arr": [7, 8, 9, 16, 16, 27, 32, 33, 35, 35, 39, 39, 41, 42, 44, 47, 48, 50, 56, 59, 66, 69, 70, 73, 74, 76, 78, 87, 87, 89, 94, 96, 96, 98, 98], "n": 32}}, {"idx": 1, "outputs": 1, "inputs": {"arr": [40, 76, -54, -92, -28, -96, 8, 60, 28, -38, -62, -40, -16, 16, 52, 28, 70, -56, -50, 46, 68, -16, -56, 46, 42, 70, 52, -34, 86, -32, -50, 64, 36, 54, 20, 82, 84], "n": 25}}, {"idx": 2, "outputs": 1, "inputs": {"arr": [0, 0, 0, 0, 1, 1, 1], "n": 4}}, {"idx": 3, "outputs": 5, "inputs": {"arr": [15, 19, 87, 44, 15, 48, 21, 85, 90, 30, 88, 95, 48, 92, 29, 52, 46, 46, 7, 23, 96, 97, 43], "n": 19}}, {"idx": 4, "outputs": 1, "inputs": {"arr": [-98, -96, -94, -94, -94, -80, -80, -78, -64, -62, -62, -46, -42, -38, -36, -36, -34, -32, -20, -18, -16, -12, -8, -4, -4, -2, -2, 2, 6, 12, 34, 40, 42, 44, 46, 46, 50, 54, 58, 58, 70, 72, 72, 76, 78, 86], "n": 33}}, {"idx": 5, "outputs": 2, "inputs": {"arr": [0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1], "n": 13}}, {"idx": 6, "outputs": 5, "inputs": {"arr": [6, 7, 19, 36, 44, 63, 68, 72, 83], "n": 8}}, {"idx": 7, "outputs": 1, "inputs": {"arr": [-64, 12, 56, 50, 94, 6, 0, 70, -70, 46, -84, -64, 4, 76, 28, 94, -8, 24, 76, 64, -62, -34], "n": 15}}, {"idx": 8, "outputs": 2, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 21}}, {"idx": 9, "outputs": 3, "inputs": {"arr": [71, 57, 20, 8, 90, 69, 15, 62, 45, 14, 65, 20, 48, 9], "n": 10}}]
question_info.extension: lua
question_info.entry_fn_name: longest_increasing_odd_even_subsequence
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: lua __FILENAME__