-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlargest_area_of_rectangele_with_permutations.cpp
83 lines (83 loc) · 1.77 KB
/
largest_area_of_rectangele_with_permutations.cpp
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Problem Link - https://www.interviewbit.com/problems/largest-area-of-rectangle-with-permutations/
/*
int maxer(vector<vector<int>> A)
{
int n = A.size();
int m = A[0].size();
vector<vector<int>> dp(n, vector<int> (m,0));
for(int i=0; i<m; i++)
{
int pred=0;
for(int j=0; j<n; j++)
{
if(A[j][i] == 1)
{
dp[j][i] = ++pred;
}
else pred=0;
}
}
for(int i=0; i<n; i++)
{
sort(dp[i].begin(), dp[i].end());
reverse(dp[i].begin(), dp[i].end());
}
int maxy = INT_MIN;
for(int i=0; i<n; i++)
{
int maxx = INT_MIN;
for(int j=0; j<m; j++)
{
maxx = max(maxx, (j+1)*dp[i][j]);
}
maxy = max(maxy, maxx);
}
return maxy;
}
int Solution::solve(vector<vector<int> > &A) {
int maxr = maxer(A);
return maxr;
}
*/
#include <bits/stdc++.h>
using namespace std;
int maxer(vector<vector<int>> A)
{
int n = A.size();
int m = A[0].size();
vector<vector<int>> dp(n, vector<int> (m,0));
for(int i=0; i<m; i++)
{
int pred=0;
for(int j=0; j<n; j++)
{
if(A[j][i] == 1)
{
dp[j][i] = ++pred;
}
else pred=0;
}
}
for(int i=0; i<n; i++)
{
sort(dp[i].begin(), dp[i].end());
reverse(dp[i].begin(), dp[i].end());
}
int maxy = INT_MIN;
for(int i=0; i<n; i++)
{
int maxx = INT_MIN;
for(int j=0; j<m; j++)
{
maxx = max(maxx, (j+1)*dp[i][j]);
}
maxy = max(maxy, maxx);
}
return maxy;
}
int main()
{
vector<vector<int>> A = A = {{1, 0, 1},{0, 1 ,0},{1, 0, 0}};
int maxr = maxer(A);
return maxr;
}