The elements present in the extreme left and right can never be peak elements.
Input Format:
The first line contains N.
The second line contains N integer values separated by a space.
The first line contains N.
The second line contains N integer values separated by a space.
Output Format:
The first line contains the count of peak elements.
The first line contains the count of peak elements.
Boundary Conditions:
2 <= N <= 1000
2 <= N <= 1000
Example Input/Output 1:
Input:
5
1 2 3 1 3
Input:
5
1 2 3 1 3
Output:
1
1
Example
Input/Output 2:
Input:
5
1 2 3 4 5
Input:
5
1 2 3 4 5
Output:
0
0
Source code:
n,c=int(input()),0
v=[int(i) for i in input().split()]
for i in range(1,n-1):
if v[i]>v[i-1] and v[i]>v[i+1]:
c+=1;
print(c)
No comments:
Post a Comment