#197. 计算徒步路径中的大步数
计算徒步路径中的大步数
Count Big Steps
Background
Congcong is planning a hiking trip. He has a map recording the altitudes along the trail.
Problem Description
(A variation on the sumHeights problem.) We have an array of heights, representing the altitude along a walking trail. Given start/end indexes into the array, return the number of "big" steps for a walk starting at the index and ending at the index. We'll say that step is big if it is or more up or down. The and index will both be valid indexes into the array with .
Input Format
The input consists of a single line.
[h_0 h_1 ... h_{N-1}] start endThe first part is a list of integers enclosed in square brackets[]with elements separated by spaces, representing the array of heights. The second part consists of two integers, and , representing the starting and ending indices of the walk.
Output Format
Output to standard output in the following format.
countWherecountis the number of "big" steps.
Sample
[5 3 6 7 2] 2 4
1
[5 3 6 7 2] 0 1
0
[5 3 6 7 2] 0 4
1
Sample Explanation
For Sample 1: [5 3 6 7 2] 2 4
The start index is , and the end index is .
From to : , not a big step.
From to : , this is a big step.
There is a total of big step.
Constraints
Time limit: 1s, Memory limit: 1024KiB for each test case.