ksykulev/Skyline

Finding the area of a city skyline with square buildings
Switch branches/tags
Nothing to show
Fetching latest commitâ€¦
Cannot retrieve the latest commit at this time.
 Failed to load latest commit information. lib test README array.js interval.js skyline.html skyline.js

```This is a problem I got asked during an interview that I found pretty interesting. So I decided to take a quick stab at coding it up. Probably not the most elegent or efficient way of solving it, but it gets the job done (I THINK..)

The Problem:
You are standing on the New Jersey coast looking across the river facing New York. Write an algorithm that will find the total area the skyline takes up. For simplicity assume the buildings are only square shapes.

You get an array of buildings that make up the city in this form:
[x1,x2,height]

If some or all of the interval of build B overlaps the interval of build A, assume that they are at different depths in the city. In cases like this make sure you don't double count the area that these buildings combined take up.

Here is an example:
[[11,14,2],[12,13,5]]

++++
|  |
|  |
|  |
++++++++++
|  *  *  |
|  *  *  |
-------|--|--|--|------------------
11 12 13 14

Total Area: 9

Usage:
Just load up skyline.html in a browser that support canvas and html5.

Tests: