title: Length Longest Strict Bitonic Subsequence
signature: length_longest_strict_bitonic_subsequence <- function(arr, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(78L), 0L, 
          0L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(-6L, -18L, -48L, 58L, -54L, 76L, 80L, -56L, 86L, 58L, -86L, -86L, -88L, 32L, 12L, 58L, 58L, -16L, 86L, -24L, 84L, 86L, 36L, 18L, 30L, -32L, -4L, -36L, -72L, -4L, 42L, 94L), 18L, 
          1L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 1L), 1L, 
          1L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(92L, 26L, 72L, 8L, 66L, 28L, 34L, 61L, 28L), 5L, 
          1L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-86L, -82L, -76L, -68L, -66L, -64L, -62L, -56L, -48L, -42L, -38L, -30L, -22L, -18L, -10L, -10L, -4L, -2L, 4L, 28L, 42L, 44L, 50L, 50L, 56L, 58L, 60L, 76L, 82L, 86L, 86L, 98L), 25L, 
          1L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 0L, 1L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 0L), 17L, 
          3L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(3L, 4L, 8L, 9L, 12L, 13L, 16L, 19L, 23L, 25L, 29L, 31L, 34L, 36L, 38L, 41L, 42L, 47L, 49L, 50L, 51L, 51L, 58L, 63L, 66L, 70L, 73L, 74L, 75L, 75L, 75L, 76L, 76L, 80L, 82L, 83L, 83L, 84L, 86L, 89L, 90L, 91L, 91L, 95L, 96L), 44L, 
          4L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(4L, -76L, 60L, 48L, -14L, 72L), 3L, 
          1L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(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), 17L, 
          2L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(66L, 80L, 79L, 72L, 1L, 67L, 20L, 67L, 32L, 40L, 22L, 64L, 58L, 67L, 10L, 21L, 37L, 49L), 15L, 
          2L
      )))
  
  }
  
  main()
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;
  }