Biggest container
Inputs
heights is a list of 0 to 12 whole numbers, each from 0 to 12.
Your tasks
- Set
leftto 0,rightto the last position andbestto 0. - Use a
whileloop that runs whileleft < right. The container between them holds(right - left)times the shorter of the two heights. Updatebestwith it. - Then move the marker with the shorter height inward.
- Complete
bestContainerso it returnsbest. Return it, do not print it.
Example
With heights = [1, 8, 6, 2, 5, 4, 8, 3, 7], bestContainer returns 49.
Rules
- Fewer than 2 heights give 0.
Test data
TEST DATA 1: heights is [1, 8, 6, 2, 5, 4, 8, 3, 7]
TEST DATA 2: heights is []
Practice focus
Two pointers and sliding windows: loops that move two positions instead of one. Two pointers and sliding windows turn many quadratic answers into linear ones.