LeetCode Entry
1637. Widest Vertical Area Between Two Points Containing No Points
Max x window between xy points
1637. Widest Vertical Area Between Two Points Containing No Points easy
blog post
substack

Join me on Telegram
https://t.me/leetcode_daily_unstoppable/446
Problem TLDR
Max x window between xy points
Intuition
We can sort points by x and scan max window between them
Complexity
-
Time complexity: \(O(nlog(n))\)
-
Space complexity: \(O(n)\)
Code
fun maxWidthOfVerticalArea(points: Array<IntArray>): Int =
points
.sortedBy { it[0] }
.windowed(2)
.maxOf { it[1][0] - it[0][0] }