2021. Brightest Position on Street

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2021

class Solution:
    def brightestPosition(self, lights: List[List[int]]) -> int:
        d = defaultdict(int)
        for i, j in lights:
            l, r = i - j, i + j
            d[l] += 1
            d[r + 1] -= 1
        res = s = mx = 0
        for k in sorted(d):
            s += d[k]
            if mx < s:
                mx = s
                res = k
        return res