export function maxArea(alturas) {
let pointer1 = 0;
let pointer2 = alturas.length-1
let maxArea = 0
while (pointer1 < pointer2) {
let minHeight = Math.min(alturas[pointer1], alturas[pointer2])
let currentArea = (pointer2-pointer1) * minHeight
if (currentArea > maxArea) {
maxArea = currentArea
}
if (alturas[pointer1] < alturas[pointer2]) {
pointer1 ++
} else {
pointer2 --
}
}
return maxArea
}
¿Quieres ver más aportes, preguntas y respuestas de la comunidad?