Connection Status:
Competition Arena > HillClimber
SRM 722 · 2017-10-11 · by erinn · Brute Force
Class Name: HillClimber
Return Type: int
Method Name: longest
Arg Types: (vector<int>)
Problem Statement

Problem Statement

You are about to go hiking. The trail consists of n segments. Some segments go uphill, others are level, and the remaining ones go downhill.

You are given a int[] height with n+1 elements. The elements of height are altitude measurements taken at the beginning of the trail and at the end of each segment.

You are concerned about long uphill climbs. Return the largest number of consecutive trail segments that go uphill.

Constraints

  • height will contain between 2 and 50 elements, inclusive.
  • Each element of height will be between 0 and 10000, inclusive.
Examples
0)
{ 1, 2, 3, 2, 2 }
Returns: 2

At the beginning of this trail there are two consecutive segments of uphill hiking: first we go from altitude 1 to altitude 2, and then we go from altitude 2 to altitude 3.

1)
{ 1, 2, 2, 3 }
Returns: 1

This trail has two uphill segments (1-2 and 2-3) but they are not consecutive.

2)
{ 1, 8, 9, 12 }
Returns: 3

The altitudes that correspond to the answer don't necessarily have to form a proper arithmetic sequence. As long as they are increasing, it is an uphill hike.

3)
{ 10, 4, 4, 2 }
Returns: 0

We never actually have any uphill segments here.

4)
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
Returns: 9

Submissions are judged against all 39 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class HillClimber with a public method int longest(vector<int> height) · 39 test cases · 2 s / 256 MB per case

Submitting as anonymous