# Codeforces Round #695 (Div. 2) Hills and valleys

Problem Link :

Below is Link of my solution

My Approach :

1. First I Calculated the The position of hills and the valleys and stored in array hv .
2. Then I calculated if there exist hill valley hill or valley hill valley in consecutive manner if exists then i will reduce 3 from total of hills and valleys
3. Also if second step fails then i calculated if there exist and hill valley or valley hill consecutively
if does i will reduce total by 2
4. if total number of hills and valleys are less than 2
i put 0 . as i can reduce it to 0 ;

My Solution is stuck to one case where expected output is 1 but my solution giving 0
Other all testcase are pass

If anyone can figure out the testcase Plz tell
on which it is failing .

Yeah , I too got WA on TC 3 several times but,
Your even passes the difficult test cases and it seems to me that there must be some corner case errors.
Do check this solution for easier implementation

I got the testcase
where output should be 3 where i my solution giving 2

1
13
14 23 2 2 4 12 2 3 23 29 3 3 27

For this testcase
condition for
4 12 2 3 23
This should be handled
here 12 is hill and 2 is valley
here if you make 2 as 12
to destroy hill 12 and valley 2
the new valley for 3 is created which must be added to solution

Also If you do 12 as 2 new hill is created which is 4

This might be the corner case .

Yes , you got that correctly .
I have already mentioned the easiest implementation of the question.
Do check that for convenience.

Yes even I found it from the solution provided by you
Thx for that solution bro .