kt: add «11. Container With Most Water»

URL:	https://leetcode.com/problems/container-with-most-water/
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2025-02-08 23:44:24 +01:00
parent 17451369aa
commit f15c12a030
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

View file

@ -0,0 +1,21 @@
class Solution {
fun maxArea(height: IntArray): Int {
var foundMax = 0
var (l, r) = 0 to height.size - 1
while (l < r) {
foundMax =
listOf(
foundMax,
(r - l) * listOf(height[l], height[r]).min(),
).max()
when {
height[l] < height[r] -> l++
else -> r--
}
}
return foundMax
}
}