problem https://hack.codingblocks.com/app/contests/987/p/194
I am not able to find the logic of this problem
Think of it this way. There are three possibilities in total
- The sequence is completely increasing.
- The sequence is completely decreasing
- The sequence is first decreasing then increasing.
These are the three situations where we print true or else we print false.
If we plot the graph for the three situations the first one will be a simple increasing curve.
The second one will be a simple decreasing curve.
Both of these cases can be checked and verified using a simple loop.
The only case you are left to check now is the third one which forms a V-like graph , first decreasing then increasing.
To check this we can see how many turning points are there in the sequence. A turning point would be the element before which all elements were increasing and from thereon start decreasing or before which all elements were decreasing and then start increasing.
Assume your sequence to be decreasing at first since that is specified in the problem that the sequence is first decreasing. After that check for such turning points. From the graph we can infer that this would be the lowermost point in the V-graph. Also there would be only one such point atmost and no more. So simply count such turning points. Check if the no of turning points is more than 1. If so , print false. Else print true.
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.