# Largest Bitonic Subarray(Contest)

Problem Statement :&#x20;

You are given an array of positive integers as input. Print the length of the largest subsequence such subsequence in which the values are arranged first in strictly ascending order and then in strictly descending order. Such a subsequence is known as bitonic sub-array. A purely increasing or purely decreasing subsequence will also be considered as a bitonic sequence with the other part empty.

Note: that the elements in bitonic sub-array need not be consecutive in the given array but the order should remain same. Input First line contains N, size of array. Second line contains elements of array separated by space.

Constraints: 1 < = N < = 10^3 1 < = ai < = 10^6 Output Length of Largest Bitonic Sub-Array Example Input: 6 15 20 20 6 4 2

Output: 5

Explanation: Testcase 1: Here, longest Bitonic sub-array is {15, 20, 6, 4, 2} which has length = 5.

link:<https://my.newtonschool.co/playground/code/wv0h14nnmazu/>

````java
```java
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework

// don't change the name of this class
// you can add inner classes if needed
class Main {
    public static void main (String[] args) {
        Scanner sc= new Scanner(System.in);
        int n = sc.nextInt();
        int arr[] = new int[n];
        for(int i=0; i<n ; i++){
            arr[i] = sc.nextInt();
        }
        System.out.println(lbs(arr, n));
    }
        static int lbs(int arr[] , int n){
            int i, j;
            int [] lis = new int [n];
            for(i=0; i<n; i++){
                lis[i] =1;
            }
            for(i=1; i<n; i++){
                for(j=0; j<i; j++){
                    if(arr[i] > arr[j] && lis[i] < lis[j] +1){
                        lis[i] = lis[j] +1;
                    }
                }
            }
            int lds[] = new int[n];
            for(i=0; i<n;i++){
                lds[i] =1;
            }
            for(i= n-2; i>=0; i--){
                for(j=n-1; j>i; j--){
                    if(arr[i]> arr[j] && lds[i] < lds[j] +1){
                        lds[i] = lds[j] +1;
                    }
                }
            }
            int max = lis[0] + lds[0] -1;
            for(i= 1; i< n; i++){
                if(lis[i] + lds[i] -1 > max){
                    max=lis[i] + lds[i]-1;
                }
            }
            return max;
        }
    }
```
````


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://anand-aryan.gitbook.io/placecom-question/largest-bitonic-subarray-contest.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
