2345. Finding the Number of Visible Mountains
On This Page
class Solution:
def visibleMountains(self, peaks: List[List[int]]) -> int:
arr = [(x - y, x + y) for x, y in peaks]
cnt = Counter(arr)
arr.sort(key=lambda x: (x[0], -x[1]))
res, cur = 0, -inf
for l, r in arr:
if r <= cur:
continue
cur = r
if cnt[(l, r)] == 1:
res += 1
return res