Write a recursive method named largestRectangleArea
that accepts an array of bar heights as its parameter and finds the largest rectangular area that can be drawn in a contiguous region inside those bars.
For example, if the bar heights are {1, 2, 1, 6, 5, 2, 3}
, the bars could be thought of as follows:
#
# #
# #
# # #
# # # # #
# # # # # # #
1 2 1 6 5 2 3
The largest rectangle that can be made within these bars has an area of 10 (2 * 5):
#
+---+
|# #|
|# #|
|# #| #
# |# #|# #
# # #|# #|# #
+---+
1 2 1 6 5 2 3
If the array is empty, return 0
.
If it contains only a single bar, return that bar's height.