#3531

Count Covered Buildings

medium · 58.7% accepted · 440 likes · top 55%

array · hash table · sorting

Description

You are given a positive integer n, representing an n x n city. You are also given a 2D grid buildings, where buildings[i] = [x, y] denotes a unique building located at coordinates [x, y].

A building is covered if there is at least one building in all four directions: left, right, above, and below.

Return the number of covered buildings.

Solution