Intermedio35 pts
Container With Most Water
Traducción al español en progresoEl contenido detallado de esta lección aún se está traduciendo. Mientras tanto, se muestra en inglés.
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)
Entrada
Line 1: n. Line 2: n space-separated integers (heights).
Salida
The maximum area.
Ejemplo
9 1 8 6 2 5 4 8 3 7
Esperado
49
Loading editor…
Resultado
Sin salida aún. Ejecuta tu código para ver resultados.