title: Length Longest Strict Bitonic Subsequence
signature: function length_longest_strict_bitonic_subsequence(arr, n)
source_py: def length_longest_strict_bitonic_subsequence(arr, n):
      (inc, dcr) = (dict(), dict())
      (len_inc, len_dcr) = (([0] * n), ([0] * n))
      longLen = 0
      for i in range(n):
          len = 0
          if (inc.get((arr[i] - 1)) in inc.values()):
              len = inc.get((arr[i] - 1))
          inc[arr[i]] = len_inc[i] = (len + 1)
      for i in range((n - 1), (- 1), (- 1)):
          len = 0
          if (dcr.get((arr[i] - 1)) in dcr.values()):
              len = dcr.get((arr[i] - 1))
          dcr[arr[i]] = len_dcr[i] = (len + 1)
      for i in range(n):
          if (longLen < ((len_inc[i] + len_dcr[i]) - 1)):
              longLen = ((len_inc[i] + len_dcr[i]) - 1)
      return longLen
source_cpp: int length_longest_strict_bitonic_subsequence(vector<int> arr, int n) {
    unordered_map < int, int > inc, dcr;
    int len_inc [ n ], len_dcr [ n ];
    int longLen = 0;
    for ( int i = 0;
    i < n;
    i ++ ) {
      int len = 0;
      if ( inc . find ( arr [ i ] - 1 ) != inc . end ( ) ) len = inc [ arr [ i ] - 1 ];
      inc [ arr [ i ] ] = len_inc [ i ] = len + 1;
    }
    for ( int i = n - 1;
    i >= 0;
    i -- ) {
      int len = 0;
      if ( dcr . find ( arr [ i ] - 1 ) != dcr . end ( ) ) len = dcr [ arr [ i ] - 1 ];
      dcr [ arr [ i ] ] = len_dcr [ i ] = len + 1;
    }
    for ( int i = 0;
    i < n;
    i ++ ) if ( longLen < ( len_inc [ i ] + len_dcr [ i ] - 1 ) ) longLen = len_inc [ i ] + len_dcr [ i ] - 1;
    return longLen;
  }
question_info.entry_fn_name: length_longest_strict_bitonic_subsequence
question_info.entry_cls_name: Solution
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
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({78}, 0, 0)
      print(string.format("TEST-0...%s",result))
  
      result = driver({-6, -18, -48, 58, -54, 76, 80, -56, 86, 58, -86, -86, -88, 32, 12, 58, 58, -16, 86, -24, 84, 86, 36, 18, 30, -32, -4, -36, -72, -4, 42, 94}, 18, 1)
      print(string.format("TEST-1...%s",result))
  
      result = driver({0, 1}, 1, 1)
      print(string.format("TEST-2...%s",result))
  
      result = driver({92, 26, 72, 8, 66, 28, 34, 61, 28}, 5, 1)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-86, -82, -76, -68, -66, -64, -62, -56, -48, -42, -38, -30, -22, -18, -10, -10, -4, -2, 4, 28, 42, 44, 50, 50, 56, 58, 60, 76, 82, 86, 86, 98}, 25, 1)
      print(string.format("TEST-4...%s",result))
  
      result = driver({0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0}, 17, 3)
      print(string.format("TEST-5...%s",result))
  
      result = driver({3, 4, 8, 9, 12, 13, 16, 19, 23, 25, 29, 31, 34, 36, 38, 41, 42, 47, 49, 50, 51, 51, 58, 63, 66, 70, 73, 74, 75, 75, 75, 76, 76, 80, 82, 83, 83, 84, 86, 89, 90, 91, 91, 95, 96}, 44, 4)
      print(string.format("TEST-6...%s",result))
  
      result = driver({4, -76, 60, 48, -14, 72}, 3, 1)
      print(string.format("TEST-7...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 17, 2)
      print(string.format("TEST-8...%s",result))
  
      result = driver({66, 80, 79, 72, 1, 67, 20, 67, 32, 40, 22, 64, 58, 67, 10, 21, 37, 49}, 15, 2)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": 0, "inputs": {"arr": [78], "n": 0}}, {"idx": 1, "outputs": 1, "inputs": {"arr": [-6, -18, -48, 58, -54, 76, 80, -56, 86, 58, -86, -86, -88, 32, 12, 58, 58, -16, 86, -24, 84, 86, 36, 18, 30, -32, -4, -36, -72, -4, 42, 94], "n": 18}}, {"idx": 2, "outputs": 1, "inputs": {"arr": [0, 1], "n": 1}}, {"idx": 3, "outputs": 1, "inputs": {"arr": [92, 26, 72, 8, 66, 28, 34, 61, 28], "n": 5}}, {"idx": 4, "outputs": 1, "inputs": {"arr": [-86, -82, -76, -68, -66, -64, -62, -56, -48, -42, -38, -30, -22, -18, -10, -10, -4, -2, 4, 28, 42, 44, 50, 50, 56, 58, 60, 76, 82, 86, 86, 98], "n": 25}}, {"idx": 5, "outputs": 3, "inputs": {"arr": [0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0], "n": 17}}, {"idx": 6, "outputs": 4, "inputs": {"arr": [3, 4, 8, 9, 12, 13, 16, 19, 23, 25, 29, 31, 34, 36, 38, 41, 42, 47, 49, 50, 51, 51, 58, 63, 66, 70, 73, 74, 75, 75, 75, 76, 76, 80, 82, 83, 83, 84, 86, 89, 90, 91, 91, 95, 96], "n": 44}}, {"idx": 7, "outputs": 1, "inputs": {"arr": [4, -76, 60, 48, -14, 72], "n": 3}}, {"idx": 8, "outputs": 2, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 17}}, {"idx": 9, "outputs": 2, "inputs": {"arr": [66, 80, 79, 72, 1, 67, 20, 67, 32, 40, 22, 64, 58, 67, 10, 21, 37, 49], "n": 15}}]