11. Container With Most Water

class Solution {

    /**
     * @param Integer[] $height
     * @return Integer
     */
    function maxArea($height) {
        $left = 0;
        $right = count($height) - 1;
        $max = 0;
        while ($left < $right) {
            $water = min($height[$left], $height[$right]) * ($right - $left);
            $max = max($max, $water);
            if ($height[$left] < $height[$right]) {
                $left++;
            } else {
                $right--;
            }
        }

        return $max;
    }
}

Last updated