Trains the technique from
LeetCode 11Container With Most WaterThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A stone walkway is lined with pillars, one pillar every metre. pillars[i] is the height in metres of the pillar at metre mark i. A stump left over from an old pillar has height 0.
A crew hangs one rectangular banner across the walkway. They pick two pillars, run a level rope between them and let the fabric hang from the rope all the way down to the paving. Because the rope has to sit at the same height on both pillars, it can be tied no higher than the lower of the two pillar tops, and the banner's height equals the rope's height. The banner's width is the gap in metres between the two chosen pillars.
Return the largest area, in square metres, that a single banner can cover. The rope is never tied at a tilt, and pillars standing between the chosen two are ignored: the fabric hangs freely past them.
Example 1
Tying to marks 1 and 2 gives a rope at height 8 across a gap of 1 metre. Reaching for the widest gap, marks 0 and 3, only allows height 1 over 3 metres, which is 3 square metres.
Example 2
The two end pillars are both 3 metres tall and stand 5 metres apart, so the banner covers 15 square metres. The short pillars in between do not get in the way.
Example 3
With only one pair available, the rope sits at 4 metres across a 1 metre gap.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def largest_banner(pillars: list[int]) -> int:public int largestBanner(int[] pillars)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.