ColumnDiagramPerimeter
SRM 419 · 2008-09-24 · by andrewzta
SRM 419 · 2008-09-24 · by andrewzta · Simple Search, Iteration
Problem Statement
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.
Examples
0)
{2,3,5,6,1}
Returns: 22
This column diagram is shown on the picture in the problem statement.
1)
{3,2,1}
Returns: 12
2)
{2,2}
Returns: 8
3)
{1,2,1}
Returns: 10
4)
{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.
Coding Area
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