loading...

re: Container with Most Water VIEW POST

FULL DISCUSSION
 

I came up with something slightly different:

pub fn max_area(height: Vec<i32>) -> i32 {
    let mut best = 0;

    for left in 0..height.len() {
        for right in (left + 1)..height.len() {
            let width = (right - left) as i32;
            let height = height[left].min(height[right]);
            let volume = width * height;

            best = best.max(volume);
        }
    }

    best
}
 

This is correct, but have you considered the runtime complexity? What happens if a large input, say 10000 elements is provided?

Take a look at this playground for an example (it is likely to timeout so you may wish to copy the code and run it locally) :)

code of conduct - report abuse