Can i make the code even better and efficient?
I want your review.
Increasing Decreasing sequence qstn
Hello @dbhavanishankar89,’
I would suggest you to submit your code once.
It is not satisfying all the testcases.
Example:
-
Strictly Decreasing only.
5
5
4
3
2
1
Expected Output:
True
Your Output:
False -
There is a significance of the word strictly.
It means you cannot have same values in the consecutive places in the sequence.
5
1
1
2
3
4
Expected Output:
False
Your Output:
True
Correct these.
You can check the way i wrote code for this problem here, but only after correcting your code:
Hope, this would help.
Give a like, if you are satisfied.
No it satisfied all the cases.i think you are confused …First number indicates the number of inputs we are giving
I just submitted your code and surprisingly it passed all the testcases.
This is because the testcases that they have for the question is not covering the cases that i have specified in my previous reply.
I have conveyed the same to your mentors and they will update these testcases soon.
For now in support of what i explained earlier, you can read this:
http://mathworld.wolfram.com/StrictlyIncreasingFunction.html
Give a like, if you are satisfied.
No…you mentioned above case I.e 5 4 3 2 1…my output gives true only…
All the cases I thought in my own way also passed correctly.
Please give an example where my code fails…And explain well.
Sure @dbhavanishankar89,
Here’s the SS of Example 1.
When the sequence is strictly decreasing
The output should be true
But, your code is printing false.
SS of Example 2.
You cannot have the same element at adjacent positions in a strict function.
So, the output should be false.
But, your code is producing true.
I hope that I have explained well, this time.
Yaa …got it…May be the question is only for increasing /decreasing sequence not strictly .
But anyway thanks.
Is my way of writing code is efficient?
Please review my code excluding that strict case.
Help me improve
Yes, it is efficient.
Don’t forget to modify it for the completely decreasing sequence as I have specified in the first example.
Give a like, if you are satisfied.
Please, mark this doubt as resolved, if you have no more issues regarding this problem.
For first case it is giving correct output only I.e 5 4 3 2 1
Okay, i got this,
You have confused the testcase that i have specified(i.e. 5 5 4 3 2 1) with the wrong testcase i.e. 5 4 3 2 1
cin>>N;
cin>>n;
//Capital ‘N’ i.e. the first input is the number of elements in the sequence
// lowercase ‘n’ represents the elements of the sequence.
Correct me if I am wrong.
Now, consider the test case 5 4 3 2 1
N=5
That means there should be 5 elements in the sequence. Correct?
but, 4 3 2 1 are only 4 elements.
So, the testcase you are considering don’t have all elements.
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;
}