Container With Most Water
📖 Scenario: Imagine you have a row of vertical lines drawn on a flat surface. Each line has a height. You want to find two lines that, together with the surface, form a container that holds the most water.This is like choosing two walls to hold water between them. The water amount depends on the shorter wall and the distance between the walls.
🎯 Goal: You will write a program to find the maximum amount of water that can be held between two lines from a list of heights.
📋 What You'll Learn
Create a list called
heights with the exact values: [1, 8, 6, 2, 5, 4, 8, 3, 7]Create a variable called
max_water and set it to 0Use a
while loop with variables left and right to find the maximum water containerPrint the value of
max_water💡 Why This Matters
🌍 Real World
This problem models situations where you want to maximize capacity between boundaries, like designing containers, dams, or storage tanks.
💼 Career
Understanding two-pointer techniques and optimization is useful for coding interviews and real-world problems involving arrays and searching.
Progress0 / 4 steps