We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent dac390d commit 7db2033Copy full SHA for 7db2033
src/hard/largest_rectangle_in_histogram.rs
@@ -34,6 +34,21 @@ pub fn largest_rectangle_area(heights: Vec<i32>) -> i32 {
34
max_area
35
}
36
37
+/*
38
+ Algorithm - Stack
39
+ - Push index to stack if stack is empty or current height is greater than or equal to the height at index at top of stack
40
+ - If current height is less than the height at index at top of stack, pop the index from stack and calculate area
41
+ - Area = height[top] * (stack.is_empty() ? i : i - stack.top() - 1)
42
+ - Update max_area
43
+ - Pop all the indexes from stack and calculate area
44
45
46
+ - Return max_area
47
+
48
+ Time Complexity - O(n)
49
+ Space Complexity - O(n)
50
+ */
51
52
#[cfg(test)]
53
mod tests {
54
use super::*;
0 commit comments