From fab65754caa4c3299f969da7f7cafceb348f7469 Mon Sep 17 00:00:00 2001 From: Vaishnavi Gawale Date: Sat, 21 Feb 2026 22:26:15 -0500 Subject: [PATCH] Done Graph-1 --- find-the-town-judge.py | 18 ++++++++++ the-maze.py | 77 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 find-the-town-judge.py create mode 100644 the-maze.py diff --git a/find-the-town-judge.py b/find-the-town-judge.py new file mode 100644 index 0000000..df0786f --- /dev/null +++ b/find-the-town-judge.py @@ -0,0 +1,18 @@ +''' Time Complexity : O(V + E) + Space Complexity : O(V) + Did this code successfully run on Leetcode : Yes + Any problem you faced while coding this : No + +''' + +class Solution: + def findJudge(self, n: int, trust: List[List[int]]) -> int: + indegree = [0] * (n+1) + for i,j in trust: + indegree[j] += 1 + indegree[i] -= 1 + for i in range(1,n+1): + if indegree[i] == n-1: + return i + + return -1 \ No newline at end of file diff --git a/the-maze.py b/the-maze.py new file mode 100644 index 0000000..6ce7789 --- /dev/null +++ b/the-maze.py @@ -0,0 +1,77 @@ +#--------Solution 1 : BFS--------------- +''' Time Complexity : O(m*n) + Space Complexity : O(m*n) + Did this code successfully run on Leetcode : Yes + Any problem you faced while coding this : No + +''' + +class Solution: + def hasPath(self, maze: List[List[int]], start: List[int], destination: List[int]) -> bool: + m, n = len(maze),len(maze[0]) + dirs = [(0,1),(0,-1),(1,0),(-1,0)] + q = deque() + q.append((start[0],start[1])) + maze[start[0]][start[1]] = 2 + while q: + i, j = q.pop() + for dir in dirs: + r = dir[0] + i + c = dir[1] + j + + while 0<=r bool: + m, n = len(maze),len(maze[0]) + dirs = [(0,1),(0,-1),(1,0),(-1,0)] + self.destination = destination + + def dfs(i, j, maze): + if [i,j] == destination: + return True + maze[i][j] = 2 + + for dir in dirs: + r = dir[0] + i + c = dir[1] + j + + while 0<=r