Container with most water
Asked at DE Shaw
You're given n vertical lines; line i has height height[i] and stands at x-coordinate i. Choose two lines that, together with the x-axis, contain the most water. The water level is set by the shorter line, so the area between lines i and j is .
height = [1, 8, 6, 2, 5, 4, 8, 3, 7]
-> 49 # lines at indices 1 and 8: (8 - 1) * min(8, 7)
Return the maximum area. Aim for , and be ready to justify why your pointer move is safe.
Show a hint
Start with the widest container. If you move a pointer inward you lose width, which pointer could possibly be worth moving?
Your answer
This one is open-ended. Work it through, then check your reasoning against the full solution.