i didn’t get this question actually, i think every sequence can be arranged in increacing and decreasing order.
So, can please tell atleast one example in which it’s output will be FALSE
Increasing decreacing sequence
in this problem you have to basically consider 4 cases
the sequence can be either monotonically increasing
the sequence can be either monotonically decreasing
it can be either first increasing then decreasing
it can be either first decreasing then increasing.
for this input
1
2
3
2
1
the answer would be “false”
if any of the case is true then answer is “yes”
I am even unable to start thinking for the solution because i didn’t get question. please help with this
Hello,
You are given a sequence of numbers.
you don’t have to split the sequence.
what you are required to do is to keep track of whether the sequence is:
- strictly increasing (entirely) eg. [1,2,3,4]
- strictly decreasing (entirely) eg. [5,3,2,0]
- 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 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 than 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.
sir , i am stuck after doing this much:
sir , i am stuck after doing this much:#include #include<math.h> using namespace std; //what you are required to do is to keep track of whether the sequence is: // //strictly increasing (entirely) eg. [1,2,3,4] //strictly decreasing (entirely) eg. [5,3,2,0] //First strictly decreasing than strictly increasing eg. [5,3,1,4,6] int main() { int no,f=0,a=-1; char ch=‘r’;//ch is initialized to any random letter cin>>no; a=no; cin>>no; //check for strictly DECREASING and firstly decreasing if(no<a) { while(no<a||ch!=’\n’) { a=no; cin>>no; ch=cin.get(); if(no>a&&ch!=’\n’) { f=1; break; } } } // INCREASING while(ch!=’\n’||no>a) { a=no; cin>>no; if(no<a) { f=1;break; } ch=cin.get(); } if(f==0) cout<<“True”; else cout<<“False”; }
Please, paste your code on coding blocks IDE and share the link with me.
It would be easier for me to debug your code.
cin>>no;
a=no;
cin>>no;
Why are you entering no twice?
Can you specify it’s purpose?
so, that i can get atlest two member of series. otherwise it would be difficult to think for a pattern of series with only one member known.
But the first no is the number of elements in the sequence.
Then in while loop, you are checking between n0 and a.
But for first iteration, n would be no. of elements.
So, how can you compare n with a?