Tap here to switch tabs
Problem
Submissions

Problem: Count Covered Buildings

med
30 min
Try to solve the Count Covered Buildings problem.

Statement

You are given an integer n representing an n $ imes$ n grid and a 2extD2 ext{D} integer array buildings, where buildings[i] = [x, y] denotes the coordinates of a building on the grid.

A building at [x, y] is considered covered if there is at least one building in all four directions:

  • Above: a building at [x', y] with x′<xx' < x

  • Below: a building at [x', y] with x′>xx' > x

  • Left: a building at [x, y'] with y′<yy' < y

  • Right: a building at [x, y'] with y′>yy' > y

Return the total number of covered buildings.

Constraints:

  • 2≤2 \leq n ≤105\leq 10^5

  • 1≤1 \leq buildings.length ≤105\leq 10^5

  • buildings[i] = [x, y]

  • 1≤x,y≤1 \leq x, y \leq n

  • All coordinates of buildings are unique.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Covered Buildings

med
30 min
Try to solve the Count Covered Buildings problem.

Statement

You are given an integer n representing an n $ imes$ n grid and a 2extD2 ext{D} integer array buildings, where buildings[i] = [x, y] denotes the coordinates of a building on the grid.

A building at [x, y] is considered covered if there is at least one building in all four directions:

  • Above: a building at [x', y] with x′<xx' < x

  • Below: a building at [x', y] with x′>xx' > x

  • Left: a building at [x, y'] with y′<yy' < y

  • Right: a building at [x, y'] with y′>yy' > y

Return the total number of covered buildings.

Constraints:

  • 2≤2 \leq n ≤105\leq 10^5

  • 1≤1 \leq buildings.length ≤105\leq 10^5

  • buildings[i] = [x, y]

  • 1≤x,y≤1 \leq x, y \leq n

  • All coordinates of buildings are unique.