-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrickWall.cpp
More file actions
41 lines (37 loc) · 814 Bytes
/
Copy pathbrickWall.cpp
File metadata and controls
41 lines (37 loc) · 814 Bytes
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
39
40
41
#include <bits/stdc++.h>
using namespace std;
// Brick Wall
class Solution
{
public:
int leastBricks(vector<vector<int>> &wall)
{
int width = 0, ans = 0;
unordered_map<int, int> mp;
for (int i = 0; i < wall.size(); i++)
{
width = 0;
for (int j = 0; j < wall[i].size() - 1; j++)
{
width += wall[i][j];
mp[width] += 1;
ans = max(ans, mp[width]);
}
}
return wall.size() - ans;
}
};
int main()
{
int n, m;
cin >> n;
vector<vector<int>> wall(n);
for (int i = 0; i < n; i++)
{
cin >> m;
wall[i].resize(m);
for (int j = 0; j < m; j++)
cin >> wall[i][j];
}
cout << Solution().leastBricks(wall);
}