title: Length Longest Strict Bitonic Subsequence
signature: class Solution {
  
      public int LengthLongestStrictBitonicSubsequence(List<int> arr, int n) {
test_code: using System;
  using System.Numerics;
  using System.Diagnostics;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Security.Cryptography;
  using System.Web.UI;
  using System.Web.Script.Serialization;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  namespace EvaluatePrediction {
      class TestRunner {
          public bool ValidateSolution(int actual, int expected){
              return new JavaScriptSerializer().Serialize(actual) == new JavaScriptSerializer().Serialize(expected);
          }
  
          public string driver(List<int> arr, int n, int expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                int pred_result = solution_cls.PLACEHOLDER_FN_NAME(arr, n); 
                if (ValidateSolution(
                      pred_result,
                      expected)){
                  return "PASSED";
                }
                return "FAILED";
              } 
              catch (Exception exception_obj)
              {
                return exception_obj.GetType().FullName;
              }
          }
          static void Main(string[] args) {
              TestRunner runner = new TestRunner();
              String result;
              result = runner.driver(
                  new List<int>{78}, 0, 
                  0
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-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
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 1}, 1, 
                  1
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{92, 26, 72, 8, 66, 28, 34, 61, 28}, 5, 
                  1
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{-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
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0}, 17, 
                  3
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{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
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{4, -76, 60, 48, -14, 72}, 3, 
                  1
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{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
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  new List<int>{66, 80, 79, 72, 1, 67, 20, 67, 32, 40, 22, 64, 58, 67, 10, 21, 37, 49}, 15, 
                  2
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
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;
  }