Implement a function to find the largest rectangle area in a histogram.
MediumProblem Statement
Implement a function to find the largest rectangle area in a histogram.
Sample Input
Histogram heights: [2, 1, 5, 6, 2, 3]
Sample Output
Largest rectangle area: 10
Limits
Time: 2s · Memory: 256 MB
Code Editor
00:00
fun largestRectangleArea(heights: Array<Int>): Int {
// Add your code here to find the largest rectangle area
}
fun main() {
val heights = arrayOf(2, 1, 5, 6, 2, 3)
println("Largest rectangle area: ${largestRectangleArea(heights)}")
}
Input
Histogram heights: [2, 1, 5, 6, 2, 3]
Expected Output
Largest rectangle area: 10