Container With Most Water
medium⏱ 15 mintypescriptchallengesproblem-solving-intermediate-
APRENDE HACIENDOPon a prueba tu intuición3 pasos
Container With Most Water
Usa los ejemplos y la explicación de la lección para comprobar tu idea.
Reflexión personal. No se envía a ningún servicio de IA.Caso de ejemplo — tu programa lee de stdin e imprime en stdout.
ENEste enunciado todavía está solo en inglés; la traducción al español está en camino.
Código inicial Given n non-negative integers representing heights of vertical lines at positions 0 to n-1, find two lines that together with the x-axis form a container that holds the most water.
Use two pointers from both ends, moving the shorter one inward.
Area = min(height[left], height[right]) * (right - left)
Example: [1,8,6,2,5,4,8,3,7] → Max area = 49 (between positions 1 and 8)
Formato de entrada
Line 1: n. Line 2: n space-separated integers (heights).
Formato de salida
The maximum area.
Restricciones
2 ≤ n ≤ 10⁵, 0 ≤ height[i] ≤ 10⁴