Adding two number at the end of array , so that increasing and decreasing sequence can be made . MAX - 2 index is assigned INT_MAX for decreasing sequence because next number of sequence must be less than it . Similarly , for Increasing sequence INT_MIN is assigned to MAX - 1 index .
arr [ MAX - 2 ] = int . MaxValue ; arr [ MAX - 1 ] = int . MinValue ; int [ , , ] dp = new int [ MAX , MAX , MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) for ( int j = 0 ; j < MAX ; j ++ ) for ( int k = 0 ; k < MAX ; k ++ ) dp [ i , j , k ] = - 1 ; return countMin ( arr , dp , n , MAX - 2 , MAX - 1 , 0 ) ; }