Skip to content

Instantly share code, notes, and snippets.

View akshit0699's full-sized avatar

Akshit Arora akshit0699

View GitHub Profile
@akshit0699
akshit0699 / RottingOranges.py
Created July 21, 2020 07:14
Rotting Oranges (leetcode)
from collections import deque
# Time complexity: O(rows * cols) -> each cell is visited at least once
# Space complexity: O(rows * cols) -> in the worst case if all the oranges are rotten they will be added to the queue
class Solution:
def orangesRotting(self, grid):
# number of rows
rows = len(grid)
def maxDistance(self, grid):
rows = len(grid)
if rows == 0:
return -1
cols = len(grid[0])
lands = collections.deque()
maxDistance = 0