-
Notifications
You must be signed in to change notification settings - Fork 0
/
Count number of free cell
38 lines (34 loc) · 1.05 KB
/
Count number of free cell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class Solution{
public:
vector<long long int> countZero(int N, int K, vector<vector<int>>& arr){
//Code Here
long freeCells = N * N;
std::vector<bool> filledRows(N);
std::vector<bool> filledCols(N);
int rowCount = 0;
int colCount = 0;
std::vector<long long> ans(K);
for (int i = 0; i < K; i++)
{
int row = arr[i][0];
int col = arr[i][1];
//if it is a new row to be filledA
if (!filledRows[row - 1])
{
freeCells -= (N - colCount);
filledRows[row - 1] = true;
rowCount++;
}
//if it is a new col to be filled
if (!filledCols[col - 1])
{
freeCells -= (N - rowCount);
filledCols[col - 1] = true;
colCount++;
}
//remaining freeCells after filling row and col
ans[i] = freeCells;
}
return ans;
}
};