-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweworkLargestTable.js
More file actions
48 lines (38 loc) · 1018 Bytes
/
weworkLargestTable.js
File metadata and controls
48 lines (38 loc) · 1018 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
42
43
44
45
46
47
48
function wework(grid) {
let largestTable = 0;
let maxHeight;
let maxWidth;
for (let i = 0; i < grid.length; i++) {
const row = grid[i];
for (let j = 0; j < row.length; j++) {
if (row[j] === "1") {
maxWidth = 1;
maxHeight = 1;
while (row[j + maxWidth] === "1") {
maxWidth++;
}
while (grid[i + maxHeight] && grid[i + maxHeight][j] === "1") {
maxHeight++;
}
if (maxWidth > largestTable) {
largestTable = maxWidth;
}
if (maxHeight > largestTable) {
largestTable = maxHeight;
}
for (let h = 1; h <= maxHeight; h++) {
for (let w = 0; w < maxWidth; w++) {
if (grid[i + h] && grid[i + h][j + w] !== "1") {
const area = h * (w + 1);
if (area > largestTable) {
largestTable = area;
}
}
}
}
}
}
}
return largestTable;
}
module.exports = wework;