content: package org.redquark.tutorials.leetcode;
  
  /**
   * @author Anirudh Sharma
   */
  public class ContainerWithMostWater {
  
      /**
       * @param height - input array of heights of lines
       * @return maximum area
       */
      private static int maxArea(int[] height) {
          // Maximum area will be stored in this variable
          int maximumArea = Integer.MIN_VALUE;
          // Left and right pointers
          int left = 0;
          int right = height.length - 1;
          // Loop until left and right meet
          while (left < right) {
              // Shorter pole/vertical line
              int shorterLine = Math.min(height[left], height[right]);
              // Update maximum area if required
              maximumArea = Math.max(maximumArea, shorterLine * (right - left));
              // If there is a longer vertical line present
              if (height[left] < height[right]) {
                  left++;
              } else {
                  right--;
              }
          }
          return maximumArea;
      }
  
      public static void main(String[] args) {
          System.out.println(maxArea(new int[]{1, 8, 6, 2, 5, 4, 8, 3, 7}));
          System.out.println(maxArea(new int[]{1, 1}));
          System.out.println(maxArea(new int[]{4, 3, 2, 1, 4}));
          System.out.println(maxArea(new int[]{1, 2, 1}));
          System.out.println(maxArea(new int[]{3, 9, 3, 4, 7, 2, 12, 6}));
      }
  }
  
  