Repository navigation
Expand file tree
/
Copy pathBestView.html
More file actions
3 lines (3 loc) · 2.37 KB
/
Copy pathBestView.html
File metadata and controls
3 lines (3 loc) · 2.37 KB
1
2
3
<html><head><title>10341. BestView</title></head><body><h1>10341. BestView</h1><h2>Problem</h2><p><td class="statText">There are several skyscrapers arranged in a row. You're interested in finding the one from which the maximal number of other skyscrapers can be seen. The i-th skyscraper can be represented as a line segment on a plane with endpoints (i, 0) and (i, <b>heights</b>[i]). A skyscraper can be seen from the roof of another skyscraper if a line segment connecting their roofs does not intersect with or touch any other skyscraper. Return the maximal number of other skyscrapers that can be seen from the roof of some skyscraper.</td></p><h2>Definition</h2><h3>Filename</h3><p>BestView.py</p><h3>Signature</h3><p>int numberOfBuildings(int[] heights)</p><h2>Constraints</h2><ul><li><td class="statText"><b>heights</b> will contain between 1 and 50 elements, inclusive. <br /></td></li><li><td class="statText">Each element of <b>heights</b> will be between 1 and 1,000,000,000, inclusive.<br /></td></li></ul><h2>Examples</h2><ul><li>numberOfBuildings([10]) = 0<td class="statText"><table><tr><td colspan="2" class="statText">There's only a single skyscraper, so you can see no other skyscrapers from its roof.
</td></tr></table></td></li><li>numberOfBuildings([5, 5, 5, 5]) = 2<td class="statText"><table><tr><td colspan="2" class="statText">From each skyscraper, you can only see its adjacent neighbors.</td></tr></table></td></li><li>numberOfBuildings([1, 2, 7, 3, 2]) = 4<td class="statText"><table><tr><td colspan="2" class="statText">You can see all the other skyscrapers from the central one.</td></tr></table></td></li><li>numberOfBuildings([1, 5, 3, 2, 6, 3, 2, 6, 4, 2, 5, 7, 3, 1, 5]) = 7<td class="statText"><table><tr><td colspan="2" class="statText"><p>You can see seven skyscrapers from the skyscraper with height 7:</p>
<p><img src="http://www.topcoder.com/contest/problem/BestView/ex3.gif" /></p></td></tr></table></td></li><li>numberOfBuildings([1000000000, 999999999, 999999998, 999999997, 999999996, 1, 2, 3, 4, 5]) = 6<td class="statText"><table><tr><td colspan="2" class="statText">You can see 6 skyscrapers from the skyscraper with height 999999996 - the nearest one to the left and all 5 skyscrapers to the right.</td></tr></table></td></li><li>numberOfBuildings([244645169, 956664793, 752259473, 577152868, 605440232, 569378507, 111664772, 653430457, 454612157, 397154317]) = 7</li></ul>