Biotonic array inc or dec

#include
using namespace std;
int main()
{
int t;
cin>>t;
int count1=0,count2=0;
while(t>0)
{
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
int b[2n];
for (int i = 0; i < n; i++)
{
b[i] =arr[i];
}
for(int i=0;i<n;i++)
{
b[n+i]=arr[i];
}
for(int i=0;i<2
n;i++)
{
if(b[i]>b[i+1])
{
count1++;

         }
          if(b[i]<b[i+1])
         {
             count2++;
             
         }
         
     }
}


	
return 0;

}
tell me further solution.on addition to this code.
Not a new code.

#include using namespace std; int main() { int t; cin>>t; int count1=0,count2=0; while(t>0) { int n; cin>>n; int arr[n]; for(int i=0;i<n;i++) { cin>>arr[i]; } int b[2n]; for (int i = 0; i < n; i++) { b[i] =arr[i]; } for(int i=0;i<n;i++) { b[n+i]=arr[i]; } for(int i=0;i<2n;i++) { if(b[i]>b[i+1]) { count1++; } if(b[i]<b[i+1]) { count2++; } } } return 0; }

Hi @Aryanomar00, the code isnt visible properly here, pls save your code here and share the URL here.

i have send you a code on ide please help me out on addition to this code.

Hi @Aryanomar00, can you tell me the approach you are trying to use here.

i am trying to make an array like 12 4 78 90 45 23 12 4 78 90 45 23

then i am trying to find the increasing and decreasing order count.

therefore i want the solution with that array 12 4 78 90 45 12 4 78 90 45 23

Hi @proRram, so what right now is happening here is that you have stored the total length of increasing numbers in given in array in count 1 and total length of decreasing numbers of arrays in count2. But we want the maximum length bitonic array. So we need to keep a track of count1 and count2 for a same segment together. Also you are adding all the lengths of increasing parts and decreasing parts, which is not to be done as we want length of only our answer.
Hint: Try to make 2 arrays one which deals with increasing part and another which deals with decreasing part and then use both of them to give out the result.

Hope this helps :slight_smile:

aryan ur approach will not work for cases if there are multiple dec inc seq
like
5 4 3 4 5 4 3 2 1 1 2 3 4 5
here ur code wont distinguish b/w sequence
5 4 3 4 5
and 5 4 3 2 1 2 3 4 5

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.