Container With Most Water
Updated
Problem statement
You are given an integer array heights. At index i, a vertical line extends from (i, 0) to (i, heights[i]).
Choose two distinct lines. Together with the horizontal axis, they form a container whose area is (right - left) * min(heights[left], heights[right]). Return the maximum area obtainable from any pair of lines.
Function
maxArea(heights: int[]) → intExamples
Example 1
heights = [1,8,6,2,5,4,8,3,7]return = 49The lines at indices 1 and 8 have limiting height 7 and width 7, producing area 49.
Example 2
heights = [1,1]return = 1The only two lines have width 1 and height 1.
Example 3
heights = [4,3,2,1,4]return = 16The first and last lines have height 4 and width 4, producing area 16.
Constraints
2 <= heights.length <= 100000.0 <= heights[i] <= 10000.
More eBay Onsite Interview questions
- Extract Hashtags from a TweetONSITE INTERVIEW · Seen Nov 2026
- Validate Ada Integer LiteralONSITE INTERVIEW · Seen Nov 2026
- Count Distinct Pairs With Sum KONSITE INTERVIEW · Seen Nov 2026
- Diameter of Binary TreeONSITE INTERVIEW · Seen Nov 2026
- Count Staircases with Strictly Increasing StepsONSITE INTERVIEW · Seen Oct 2026
- Hierarchical Permission CheckONSITE INTERVIEW · Seen Oct 2026
- Matrix MultiplicationONSITE INTERVIEW · Seen Oct 2026
- N-Queens Solution CountONSITE INTERVIEW · Seen Oct 2026
- Gas StationONSITE INTERVIEW · Seen Oct 2026
- Onion-Peel Layers of a Binary TreeONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Minimum Station Tracks for a Train ScheduleBNSF Railway · ONSITE INTERVIEWBNSF Railway interview questions
- Container With Most WaterAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Assign Cookies With Matching ParityInfosys · ONSITE INTERVIEWInfosys interview questions
- Rebalance Bank Accounts to a Minimum BalanceStripe · ONSITE INTERVIEWStripe interview questions
- Most Water Between Two LinesExpedia · ONSITE INTERVIEWExpedia interview questions
- Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
- Container With Most WaterEPAM · PHONE SCREENEPAM interview questions
- Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
- Container With Most WaterNuro · PHONE SCREENNuro interview questions
- Minimum Last-Element RelocationsChubb · OAChubb interview questions