Container With Most Water
Updated
Problem statement
You are given an integer array height of length n. The i-th value represents a vertical pillar from (i, 0) to (i, height[i]).
Choose two pillars that, together with the x-axis, form a container. The water held by pillars at indices i and j is min(height[i], height[j]) * (j - i).
Return the maximum amount of water that any pair of pillars can hold. The container may not be slanted.
Function
maxArea(height: int[]) → intExamples
Example 1
height = [1,8,6,2,5,4,8,3,7]return = 49The pillars at indices 1 and 8 have heights 8 and 7. Their width is 7, so they hold min(8, 7) * 7 = 49 units of water.
Example 2
height = [1,1]return = 1The only pair has width 1 and limiting height 1, so it holds 1 unit.
Example 3
height = [4,3,2,1,4]return = 16The first and last pillars have height 4 and are 4 units apart, so they hold 4 * 4 = 16 units.
Constraints
2 <= height.length <= 10^5.0 <= height[i] <= 10^4.
More Mastercard Phone Screen questions
- Top Three Accounts by Monthly Transaction AmountPHONE SCREEN · Seen Sep 2026
- Deduplicate a List While Preserving OrderPHONE SCREEN · Seen Jul 2026
- Employee With the Highest SalaryPHONE SCREEN · Seen Jul 2026
- Group Names by DepartmentPHONE SCREEN · Seen Jul 2026
- Credit and Debit Transaction Counts per UserPHONE SCREEN · Seen Apr 2026
- Users with Three Transactions in Sixty SecondsPHONE SCREEN · Seen Apr 2026
- Employees with the Highest and Lowest SalaryPHONE SCREEN · Seen Apr 2025
- Inactive Customers with Prior ActivityPHONE SCREEN · Seen Nov 2024
- Merchant Category Transaction SummaryPHONE SCREEN · Seen Nov 2024
- Top Customers by Six-Month Transaction AmountPHONE SCREEN · Seen Nov 2024
Similar questions at other companies
- Container With Most WaterEPAM · PHONE SCREENEPAM interview questions
- Container With Most WaterNuro · PHONE SCREENNuro interview questions
- Rebalance Bank Accounts to a Minimum BalanceRemitly · PHONE SCREENRemitly interview questions
- Container With Most WaterAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Container With Most WaterWayfair · PHONE SCREENWayfair interview questions
- Assign CookiesExpedia · PHONE SCREEN · ONSITE INTERVIEWExpedia interview questions
- Best Score Switching Between Two Sorted ArraysAdobe · PHONE SCREENAdobe interview questions
- Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
- Minimum Station Tracks for a Train ScheduleBNSF Railway · ONSITE INTERVIEWBNSF Railway interview questions
- Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions