https://hack.codingblocks.com/contests/c/474/194
https://ide.codingblocks.com/#/s/31490
Increasing Decreasing Sequence @HB
INPUT:
5
3 2 1 4 5
OUTPUT:
false
EXPECTED OUTPUT:
true
Try correcting your code.
the problem is to be solved without using arrays/lists.
You can solve it without arrays/lists also.
While taking input keep a check that the number is decreasing than the previous and use a bool variable to account when the number is increasing than previous.
100 Percent Passed
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll n; cin>>n;
ll start; cin>>start;
n--;
ll increase = 0;
while(n--)
{
ll no; cin>>no;
if((no<start && increase==0) || (no>start && increase==1))
start = no;
else if(no>start && increase==0)
{
start = no;
increase =1;
}
else
{
cout<<"false\n";
return 0;
}
}
cout<<"true\n";
// cout<<start;
return 0;
}
1 Like