Increasing decreasing sequence

#include
using namespace std;
int main() {

int num,flag=0;
cin>>num;
int arr[num];
for(int i=0;i<num;i++){
    cin>>arr[i];
}
int dif1=arr[1]-arr[0];
    if(dif1>0)
    {   
        for(int i=1;i<num;i++){
            int dif2=arr[i+1]-arr[i];
            if(dif2<0)
            break;
            
            
        }
        
            flag=1;
            
    }

    else{
        
        for(int i=1;i<num;i++){
            int dif2=arr[i]-arr[i+1];
            if(dif2>0)
            break;
        }
        
            flag=1;
    }

if(flag==1)
cout<<“true”;
else
cout<<“false”;
return 0;
}

not passing all test cases please assist

Hello @hrishikeshjanjal,

From next time share your code using Online Coding Blocks IDE.
The way you have shared it is introducing many runtime errors to it.

Steps:

  1. Paste it on Online Coding Blocks IDE.
  2. Save it there.
  3. Share the URL generated.

Now, coming back to your problem:
You are required to keep track of following:

  1. strictly increasing (entirely) eg. [1,2,3,4]
  2. strictly decreasing (entirely) eg. [5,3,2,0]
  3. First strictly decreasing than strictly increasing eg. [5,3,1,4,6]
    if yes,
    print true
    else,
    print false

strict function: which do not contain the same number at consecutive positions i.e. same values cannot occur one after other.
example: [1, 1, 2] This is not a strict function as there are two 1 at consecutive locations.

Hint: there should be no decrease in sequence if it once starts increasing i.e. first increasing then decreasing returns false. eg. [2,4,7,3,1] (not accepted)

Hope, this would help.
if you still have doubts, feel free to ask.
Give a like, if you are satisfied.

1 Like