By given an array of integers, each element represents a building. For example: int buildings[] = {1, 4, 3, 2, 3, 1}.
If I drew the buildings horizontally with a brush, how many brush strike I would use?
I should write a function that returns the number of these brush strokes. For example 5.
I can do it easily on run time O(n^2), by using 2 loops.
The external loop running on the levels of each building (according to the highest building).
The inner loop is running on the array from
0ton, and compares the difference of the height (0or1) between two near elements.
How can I do this in the O(n) time and O(n) space?
