Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    3531 - Count Covered Buildings.

    Medium

    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.

    Example 1:

    Input: n = 3, buildings = [1,2,2,2,3,2,2,1,2,3]

    Output: 1

    Explanation:

    • Only building [2,2] is covered as it has at least one building:

    • Thus, the count of covered buildings is 1.

    Example 2:

    Input: n = 3, buildings = [1,1,1,2,2,1,2,2]

    Output: 0

    Explanation:

    • No building has at least one building in all four directions.

    Example 3:

    Input: n = 5, buildings = [1,3,3,2,3,3,3,5,5,3]

    Output: 1

    Explanation:

    • Only building [3,3] is covered as it has at least one building:

    • Thus, the count of covered buildings is 1.

    Constraints:

    • <code>2 <= n <= 10<sup>5</sup></code>

    • <code>1 <= buildings.length <= 10<sup>5</sup></code>

    • buildings[i] = [x, y]

    • 1 &lt;= x, y &lt;= n

    • All coordinates of buildings are unique.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer countCoveredBuildings(Integer n, Array<IntArray> buildings)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait