Feature #2: Low Coverage Area

Implementing the "Low Coverage Area" feature for our "Cellular Operator" project.

Description

In a busy city center, our cellular operator has surveyed a mall, which happens to be rectangular in shape. They have identified locations within the mall where cellular network signals are unacceptably low. The result of the study is stored in the form of a rectangular matrix of 0s and 1s. Each cell in the matrix corresponds to a unit area in the mall. If the value in a cell of this array is 1, it means the corresponding location in the mall does not have good network coverage. The operator is considering deploying small radio sites inside the mall. These sites use beamforming technology, which enables providing coverage to a rectangular region. We need to determine the rectangle with the largest area with unacceptable coverage throughout.

We’ll be provided with an m x n matrix of 0s and 1s. We have to find the area of the largest rectangle containing only 1s since that will represent the largest, low coverage, rectangular part of the mall.

Solution

We will attempt to solve the smallest portion of the input in the original problem and gradually build to larger chunks of the input until we find the answer to the problem using the original input. To this end, we will first determine the area of the largest rectangle of 1s considering only the first row of the input. Then, we will find the area of the largest rectangle ending at the second row of input and including the first one. We will repeat this process on increasing subproblem sizes. As we keep increasing the subproblem size while maintaining the maximum area, we will find the area of the largest group of contiguous 1s in the original input.

To determine the maximum area rectangle within a subset of consecutive rows from the input, we will maintain a list, dp, with a size equal to the number of columns in the input matrix. After k iterations of our algorithm, the ith element in the dp list will hold the number of consecutive 1s in column i ending at the kth row of the input. For example, when we process the first row of the input shown above, [0 1 1], we want the list dp to hold [0 1 1]. How do we determine the maximum area of consecutive 1s in this list, meaning just the first row of the original input? We can again apply the divide and conquer strategy and look at a gradually increasing number of columns from the dp list.

As we process one column from dp, we determine the maximum area of consecutive 1s that that column is part of. For instance, if we consider the first column of dp, what’s the largest area of consecutive 1s? Since dp is [0 1 1], the answer is 0 because the first column has no 1s. How about the second column? If it were part of a rectangle of 1s, it would span the second and third column - with a width of 2, height of 1, and with an area(height * width) of 2. The same goes for the third column of dp as well. The maximum area we’ve seen so far is 2.

Next, as we process the second row [1 1 1], our dp list will be updated to dp = [1 2 2]. In the first column ending at the second row, we see a column of a single 1. In the second and third columns, there are columns of two 1s ending on the second row. You’ll note that dp is indeed representing the height of consecutive 1s in each column ...

Histogram representation of [1 2 2]
Access this course and 1400+ top-rated courses and projects.