Problem Link :
Below is Link of my solution
My Approach :
- First I Calculated the The position of hills and the valleys and stored in array hv .
- 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
- 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
- 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 .