x axis). Mountain i is given by its summit peaks[i] = [x, y]: it is an isosceles right triangle with the right angle at the summit, both slopes at 45°, and its base on the x axis from x - y to x + y.
A summit is visible if it is not inside another mountain and does not touch another mountain's slope. Identical mountains hide each other.
Return the number of visible summits.peaks=[[3, 3], [9, 3], [8, 1]] → 2
The slope of the mountain (9, 3) is at height 2 at x = 8, above the peak (8, 1), so that peak is hidden. The mountains (3, 3) and (9, 3) do not hide each other. Two peaks are visible.
peaks=[[4, 2], [4, 2], [10, 1]] → 1
The two identical mountains hide each other, so only (10, 1) is visible.
peaks=[[2, 1], [5, 4]] → 1
The slope of (5, 4) is at height 1 at x = 2, so the peak (2, 1) lies right on it and counts as hidden.
peaks=[[3, 3], [9, 3], [8, 1]]
2
Run checks the first 3 tests in your browser. Submit checks all 132 tests on the server, hidden ones included.