DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
medium
Array

Container With Most Water

**Problem Statement:** You are given an integer array `height` of length `n`. There are `n` vertical lines drawn such that the two endpoints of the `i`th 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. **Hint / Expected Approach:** Greedy two-pointer shrink shorter side **Edge Cases to Consider:** - (1) Two elements only - (2) All same heights - (3) Strictly increasing heights

Examples

Example 1
Input: [1,8,6,2,5,4,8,3,7]
Output: 49
Example 2
Input: [1,1]
Output: 1
Example 3
Input: [4,3,2,1,4]
Output: 16

Constraints

  • ▪1 <= nums.length <= 10^4
  • ▪-10^9 <= nums[i] <= 10^9
  • ▪Time complexity should be O(n) or O(n log n)

Watch Out For Edge Cases

  • ▪Two elements only
  • ▪All same heights
  • ▪Strictly increasing heights
Frequently Asked At
GoogleAmazonMicrosoftMetaAdobeUber