kt: add «452. Minimum Number of Arrows to Burst Balloons»

URL:	https://leetcode.com/problems/minimum-number-of-arrows-to-burst-balloons/
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2025-02-09 22:54:39 +01:00
parent 788199789d
commit 0da1240d26
Signed by: mfocko
SSH key fingerprint: SHA256:icm0fIOSJUpy5+1x23sfr+hLtF9UhY8VpMC7H4WFJP8

View file

@ -0,0 +1,19 @@
class Solution {
fun findMinArrowShots(points: Array<IntArray>): Int {
points.sortBy { it[0] }
var usedArrows = 1
points.drop(1).fold(points[0][1]) { maxX, it ->
when {
it[0] <= maxX -> listOf(maxX, it[1]).min()
else -> {
usedArrows++
it[1]
}
}
}
return usedArrows
}
}