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?
10000
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) :)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I came up with something slightly different:
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) :)