BestView
SRM 436 · 2009-03-11 · by Gluk
Problem Statement
Constraints
- heights will contain between 1 and 50 elements, inclusive.
- Each element of heights will be between 1 and 1,000,000,000, inclusive.
Statement by TopCoder, Inc. — view the original on the archive.
{10}
Returns: 0
There's only a single skyscraper, so you can see no other skyscrapers from its roof.
{5,5,5,5}
Returns: 2
From each skyscraper, you can only see its adjacent neighbors.
{1,2,7,3,2}
Returns: 4
You can see all the other skyscrapers from the central one.
{1,5,3,2,6,3,2,6,4,2,5,7,3,1,5}
Returns: 7
You can see seven skyscrapers from the skyscraper with height 7:
{351,239,157,185,452,129,101,173,78,81}
Returns: 8
{1000000000,999999999,999999998,999999997,999999996,1,2,3,4,5}
Returns: 6
You can see 6 skyscrapers from the skyscraper with height 999999996 - the nearest one to the left and all 5 skyscrapers to the right.
Submissions are judged against all 125 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class BestView with a public method int numberOfBuildings(vector<int> heights) · 125 test cases · 2 s / 256 MB per case