what is wrong or any better way to do it?
Increasing decreasing
getting 5 test cases corect 4 wrong.
- what’s wrong i am doing? Please tell
- is there any better approach to do it? Please explain
-
What you are doing is completely wrong because your are just calculating the number of increasing pairs till n/2 and from n/2 to n calculating decreasing pairs. But if an array is completely increasing/decreasing then also you have to print true which is why for sample case output is true but your code is printing false.
-
Actually you need not store the numbers, so it can be done without using arrays.
You can check condition while taking input and thus conclude whether it is valid or not.
The sequence can be valid even in the corner cases when the sequence is either completely increasing or completely decreasing also
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.