title: Length Longest Strict Bitonic Subsequence
signature: pub fn length_longest_strict_bitonic_subsequence(arr: Vec<i32>, n: i32) -> 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(arr: Vec<i32>, n: i32, expected: i32)->String{
      if validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected) {
        return "PASSED".to_string();
      };
      return "FAILED".to_string();
  
  }
  
  fn main() {
      println!("TEST-0...{}", driver(
        Vec::from([78]), 0, 
        0
      ));
      
      println!("TEST-1...{}", driver(
        Vec::from([-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
      ));
      
      println!("TEST-2...{}", driver(
        Vec::from([0, 1]), 1, 
        1
      ));
      
      println!("TEST-3...{}", driver(
        Vec::from([92, 26, 72, 8, 66, 28, 34, 61, 28]), 5, 
        1
      ));
      
      println!("TEST-4...{}", driver(
        Vec::from([-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
      ));
      
      println!("TEST-5...{}", driver(
        Vec::from([0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0]), 17, 
        3
      ));
      
      println!("TEST-6...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-7...{}", driver(
        Vec::from([4, -76, 60, 48, -14, 72]), 3, 
        1
      ));
      
      println!("TEST-8...{}", driver(
        Vec::from([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
      ));
      
      println!("TEST-9...{}", driver(
        Vec::from([66, 80, 79, 72, 1, 67, 20, 67, 32, 40, 22, 64, 58, 67, 10, 21, 37, 49]), 15, 
        2
      ));
      
  }
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;
  }