carsonSgit / leetcode

leetcode grind... doing whatever I can to make sure I'm not bad at CS.
4 stars 0 forks source link

Q11 Solution #4

Closed carsonSgit closed 4 months ago

carsonSgit commented 4 months ago

What is this problem

You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]).

Find two lines that together with the x-axis form a container, such that the container contains the most water.

Return the maximum amount of water a container can store.

How do I solve it

Breakdown:

  1. Go through the array, saving the area of the highest area (widht * smallest height of index).
  2. To iterate through, compare the heights of each index, the smallest height gets brought closer to the other (+/-)