NPL1701B Editorial

PROBLEM LINK:

Practice
Contest

Author: Manjunath
Tester: Manjunath
Editorialist: Prasad

DIFFICULTY:

EASY

PREREQUISITES:

ad-hoc

PROBLEM:

Given an array A of integers of size N which denotes mountain heights.You have to find how many valleys are there .

Valley is defined as an index i if A[i-1]>A[i] and A[i]< A[i+1].

EXPLANATION:

We iterate through the array indices that can possiblly form a valley and check for the condition. Index 0 and n-1 (0 indexed array) can not form a valley.

AUTHOR’S AND TESTER’S SOLUTIONS:

solution can be found here.