Max length bitonic array- runtime error

code:
include iostream
using namespace std;

int bitonic(int arr[100], int n)
{
int inc[n]; // Length of increasing subarray ending at all indexes
int dec[n]; // Length of decreasing subarray starting at all indexes
int i, max;

// length of increasing sequence ending at first index is 1
inc[0] = 1;

// length of increasing sequence starting at first index is 1
dec[n-1] = 1;

// Step 1) Construct increasing sequence array
for (i = 1; i < n; i++)
inc[i] = (arr[i] >= arr[i-1])? inc[i-1] + 1: 1;

// Step 2) Construct decreasing sequence array
for (i = n-2; i >= 0; i--)
dec[i] = (arr[i] >= arr[i+1])? dec[i+1] + 1: 1;

// Step 3) Find the length of maximum length bitonic sequence
max = inc[0] + dec[0] - 1;
for (i = 1; i < n; i++)
    if (inc[i] + dec[i] - 1 > max)
        max = inc[i] + dec[i] - 1;

return max;

}

int main()
{
int t;
cin>>t;
while(t–)
{
int n,i;
cin>>n;
int arr[100];
for(i=0;i<n;i++)
cin>>arr[i];

	bitonic(arr,n);
}
return 0;

}

Hello @vashishthkuntal.gajjar2019 please wait i am checking.

hey @vashishthkuntal.gajjar2019 corrected code :


the main error was the array size you were giving.
you have to check the constraints.
if you have any doubt you can ask here:
Happy Learning!!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.