first-completely-painted-row-or-column 1.0.0
First Completely Painted Row or Column
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1#include <bits/stdc++.h>
2
3using namespace std;
4
6{
7public:
8 int firstCompleteIndex(vector<int>& arr, vector<vector<int>>& mat)
9 {
10 int rows = mat.size();
11 int cols = mat[0].size();
12 vector<pair<int, int>> locations(rows * cols + 1); // (unique val, (x, y))
13 vector<int> counts_x(rows, 0); // (row, painted count)
14 vector<int> counts_y(cols, 0); // (column, painted count)
15
16 // construct dictionary for unique values and their locations
17 for (int i = 0; i < rows; ++i)
18 {
19 for (int j = 0; j < cols; ++j)
20 {
21 locations[mat[i][j]] = {i, j};
22 }
23 }
24
25 // find first row or column that satisfies requirement
26 for (int i = 0; i < (int)arr.size(); ++i)
27 {
28 auto [x, y] = locations[arr[i]];
29 counts_x[x]++;
30 counts_y[y]++;
31 if (counts_x[x] == cols || counts_y[y] == rows)
32 return i;
33 }
34 return -1;
35 }
36};
37
38int main()
39{
40
41 return 0;
42}
int firstCompleteIndex(vector< int > &arr, vector< vector< int > > &mat)
Definition main.cpp:8
int main()
Definition main.cpp:38