Skip to content

Commit d78d5c4

Browse files
committed
feat(leetcode): solve 1036 - Rotting Oranges
1 parent 526525e commit d78d5c4

4 files changed

Lines changed: 91 additions & 22 deletions

File tree

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,37 @@ Automatically synchronize accepted LeetCode submissions to GitHub.
99
```text
1010
████████████░░░░░░░░░░░░░░░░░░
1111
12-
Solved: 125 / 300 Problems
12+
Solved: 126 / 300 Problems
1313
1414
📊 Statistics
1515
Difficulty Solved
1616
🟢 Easy 63
17-
🟡 Medium 56
17+
🟡 Medium 57
1818
🔴 Hard 6
19-
Total 125
19+
Total 126
2020
🔥 Latest Accepted Problem
2121
2222
2323
| Field | Value |
2424
|------|------|
25-
| Problem ID | 1127 |
26-
| Title | Last Stone Weight |
25+
| Problem ID | 1036 |
26+
| Title | Rotting Oranges |
2727
| Language | Python3 |
28-
| Runtime | 3 ms |
29-
| Memory | 19.4 MB |
28+
| Runtime | 4 ms |
29+
| Memory | 19.5 MB |
3030
3131
3232
💻 Languages Used
3333
34-
- **Python3** : 60
34+
- **Python3** : 61
3535
3636
## 📚 Recent Accepted Problems
3737
38+
- 1036 Rotting Oranges
3839
- 1127 Last Stone Weight
3940
- 1014 K Closest Points To Origin
4041
- 295 Find Median From Data Stream
4142
- 11 Container With Most Water
42-
- 200 Number Of Islands
4343
4444
4545
---
@@ -81,4 +81,4 @@ Git
8181
GitHub
8282
⏰ Last Sync
8383
84-
2026-07-07 14:32:47
84+
2026-07-07 19:54:26
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"submission_id": "2059487580",
3+
"question_id": "1036",
4+
"title_slug": "rotting-oranges",
5+
"language": "python3",
6+
"language_verbose": "Python3",
7+
"runtime": "4 ms",
8+
"memory": "19.5 MB",
9+
"status_code": 10,
10+
"timestamp": 1783439208
11+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
class Solution:
2+
def orangesRotting(self, grid: List[List[int]]) -> int:
3+
from collections import deque
4+
5+
rows = len(grid)
6+
cols = len(grid[0])
7+
8+
queue = deque()
9+
10+
fresh = 0
11+
12+
for r in range(rows):
13+
for c in range(cols):
14+
15+
if grid[r][c] == 2:
16+
queue.append((r, c))
17+
18+
elif grid[r][c] == 1:
19+
fresh += 1
20+
21+
minutes = 0
22+
23+
directions = [
24+
(1,0),
25+
(-1,0),
26+
(0,1),
27+
(0,-1)
28+
]
29+
30+
while queue and fresh > 0:
31+
32+
for _ in range(len(queue)):
33+
34+
r, c = queue.popleft()
35+
36+
for dr, dc in directions:
37+
38+
nr = r + dr
39+
nc = c + dc
40+
41+
if (
42+
nr < 0 or
43+
nc < 0 or
44+
nr >= rows or
45+
nc >= cols or
46+
grid[nr][nc] != 1
47+
):
48+
continue
49+
50+
grid[nr][nc] = 2
51+
52+
fresh -= 1
53+
54+
queue.append((nr, nc))
55+
56+
minutes += 1
57+
58+
return minutes if fresh == 0 else -1

storage/stats.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
{
2-
"total": 125,
2+
"total": 126,
33
"easy": 63,
4-
"medium": 56,
4+
"medium": 57,
55
"hard": 6,
66
"languages": {
7-
"Python3": 60
7+
"Python3": 61
88
},
99
"recent_problems": [
10+
{
11+
"id": "1036",
12+
"title": "Rotting Oranges"
13+
},
1014
{
1115
"id": "1127",
1216
"title": "Last Stone Weight"
@@ -22,18 +26,14 @@
2226
{
2327
"id": "11",
2428
"title": "Container With Most Water"
25-
},
26-
{
27-
"id": "200",
28-
"title": "Number Of Islands"
2929
}
3030
],
3131
"last_problem": {
32-
"id": "1127",
33-
"title": "Last Stone Weight",
32+
"id": "1036",
33+
"title": "Rotting Oranges",
3434
"language": "Python3",
35-
"runtime": "3 ms",
36-
"memory": "19.4 MB"
35+
"runtime": "4 ms",
36+
"memory": "19.5 MB"
3737
},
38-
"last_sync": "2026-07-07 14:32:47"
38+
"last_sync": "2026-07-07 19:54:26"
3939
}

0 commit comments

Comments
 (0)