A skyline is an array of positive integers where each integer represents how tall a building is. For example, if we had the array [1,3,4,2,5,3,3] this would be the skyline in ascii art:
# # # ## ### ###### ####### Your task is to find the area of the largest rectangle in the skyline. In this case, the largest rectangle has area 12. Here is the rectangle, highlighted:
# # # ## ### RRRRRR #RRRRRR You can assume that the input contains at least one building (the length of the array is >0). This is code-golf, you know the drill.
Inspired by this Puzzling-SE post.
Test cases
[1] -> 1 [2, 2] -> 4 [3, 2, 1] -> 4 [1, 2, 3] -> 4 [1, 5, 1, 5] -> 5 [1, 4, 1, 4, 1] -> 5 [1, 4, 5, 4, 1] -> 12 [1, 5, 4, 5, 1] -> 12 [1, 2, 3, 5, 1, 3] -> 6 [1, 3, 3, 1, 4, 5, 2] -> 8 [1, 3, 3, 1, 1, 1, 1] -> 7