Skip to content

Commit f48571e

Browse files
Minimum Area to cover all ones I
1 parent 49fd9ff commit f48571e

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "e02def14",
6+
"metadata": {},
7+
"source": [
8+
"# Minimum Area to cover all Ones I"
9+
]
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": 1,
14+
"id": "738b355f",
15+
"metadata": {},
16+
"outputs": [
17+
{
18+
"name": "stdout",
19+
"output_type": "stream",
20+
"text": [
21+
"6\n"
22+
]
23+
}
24+
],
25+
"source": [
26+
"grid = [[0,1,0],[1,0,1]]\n",
27+
"\n",
28+
"rows, cols = len(grid), len(grid[0])\n",
29+
"\n",
30+
"minrows, maxrows = rows, -1\n",
31+
"mincols, maxcols = cols, -1\n",
32+
"\n",
33+
"for i in range(rows):\n",
34+
" for j in range(cols):\n",
35+
" if grid[i][j] == 1:\n",
36+
" minrows = min(minrows, i)\n",
37+
" maxrows = max(maxrows, i)\n",
38+
" mincols = min(mincols, j)\n",
39+
" maxcols = max(maxcols, j)\n",
40+
"\n",
41+
"heights = maxrows - minrows + 1\n",
42+
"breadth = maxcols - mincols + 1\n",
43+
"\n",
44+
"print(heights*breadth)"
45+
]
46+
}
47+
],
48+
"metadata": {
49+
"kernelspec": {
50+
"display_name": "Python 3",
51+
"language": "python",
52+
"name": "python3"
53+
},
54+
"language_info": {
55+
"codemirror_mode": {
56+
"name": "ipython",
57+
"version": 3
58+
},
59+
"file_extension": ".py",
60+
"mimetype": "text/x-python",
61+
"name": "python",
62+
"nbconvert_exporter": "python",
63+
"pygments_lexer": "ipython3",
64+
"version": "3.13.3"
65+
}
66+
},
67+
"nbformat": 4,
68+
"nbformat_minor": 5
69+
}

0 commit comments

Comments
 (0)