package leetcode;

/**
 * https://leetcode.com/problems/container-with-most-water/
 */
public class Problem11 {
    public int maxArea(int[] height) {
        int max = 0;
        for (int i = 0; i < height.length; i++) {
            int area = 0;
            System.out.println("idx: " + i);
            for (int j = i+1; j < height.length; j++) {
                if (height[i] < height[j]) {
                    area = height[i] * (j-i);
                    System.out.println("  area: " + area);
                } else {
                    area = height[j] * (j-i);
                    System.out.println("  area: " + area);
                }
            }
            max = Math.max(max, area);
        }
        return max;
    }
    
    public static void main(String[] args) {
        Problem11 prob = new Problem11();
        System.out.println(prob.maxArea(new int[]{2, 3, 4, 5})); // 6
        System.out.println(prob.maxArea(new int[]{2, 1})); // 1
        System.out.println(prob.maxArea(new int[]{1, 2, 1, 1, 3})); // 6
        System.out.println(prob.maxArea(new int[]{1, 2, 1, 1, 1})); // 4
    }
}

@@ -169,29 +169,24 @@
  0;%0A        
-for (
 int i = 0; i
@@ -187,920 +187,319 @@
 = 0;
- i %3C height.length; i++) %7B%0A            int area = 0;%0A            System.out.println(%22idx: %22 + i);%0A            for (int j = i+1; j %3C height.length; j++) %7B%0A                if (height%5Bi%5D %3C height%5Bj%5D) %7B%0A                    area = height%5Bi%5D * (j-i);%0A                    System.out.println(%22  area: %22 + area);%0A                %7D else %7B%0A                    area = height%5Bj%5D * (j-i);%0A                    System.out.println(%22  area: %22 + area);%0A                %7D%0A            %7D%0A            max = Math.max(max, area);%0A        %7D%0A        return max;%0A    %7D%0A    %0A    public static void main(String%5B%5D args) %7B%0A        Problem11 prob = new Problem11();%0A        System.out.println(prob.maxArea(new int%5B%5D%7B2, 3, 4, 5%7D)); // 6%0A        System.out.println(prob.maxArea(new int%5B%5D%7B2, 1%7D)); // 1%0A        System.out.println(prob.maxArea(new int%5B%5D%7B1, 2, 1, 1, 3%7D)); // 6%0A        System.out.println(prob.maxArea(new int%5B%5D%7B1, 2, 1, 1, 1%7D)); // 4
+%0A        int j = height.length - 1;%0A        while (i %3C j) %7B%0A            int area = Math.min(height%5Bi%5D, height%5Bj%5D) * (j - i);%0A            if (height%5Bi%5D %3C height%5Bj%5D) %7B%0A                i++;%0A            %7D else %7B%0A                j--;%0A            %7D%0A            max = Math.max(max, area);%0A        %7D%0A        return max;
 %0A   

Solve problem 11