ColumnDiagramPerimeter
SRM 419 · 2008-09-24 · by andrewzta
Problem Statement
A column diagram is composed of n consecutive columns arranged in a horizontal row. Each column has a width of 1, and the base of each column is on the x-axis. The heights of the columns are given in the
Return the perimeter of the given column diagram.
Constraints
- a will contain between 1 and 50 elements, inclusive.
- Each element of a will be between 1 and 50, inclusive.
Statement by TopCoder, Inc. — view the original on the archive.
{2,3,5,6,1}
Returns: 22
This column diagram is shown on the picture in the problem statement.
{3,2,1}
Returns: 12
{2,2}
Returns: 8
{1,2,1}
Returns: 10
{1,2,3}
Returns: 12
Submissions are judged against all 90 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ColumnDiagramPerimeter with a public method int getPerimiter(vector<int> a) · 90 test cases · 2 s / 256 MB per case