From 2d8a6b992236f0fdc81a0b0e56ec42a600966730 Mon Sep 17 00:00:00 2001 From: AnirudhS30 <127216139+AnirudhS30@users.noreply.github.com> Date: Sun, 12 Oct 2025 07:52:35 +0000 Subject: [PATCH] Completed Graph-1. Requesting Review --- problem_1.py | 16 ++++++++++++++++ problem_2.py | 22 ++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 problem_1.py create mode 100644 problem_2.py diff --git a/problem_1.py b/problem_1.py new file mode 100644 index 0000000..6100bf7 --- /dev/null +++ b/problem_1.py @@ -0,0 +1,16 @@ +class Solution: + def findJudge(self, n: int, trust: List[List[int]]) -> int: + if n == 1: + return 1 + + indeg = [0] * (n + 1) + outdeg = [0] * (n + 1) + + for a, b in trust: + outdeg[a] += 1 + indeg[b] += 1 + + for person in range(1, n + 1): + if indeg[person] == n - 1 and outdeg[person] == 0: + return person + return -1 \ No newline at end of file diff --git a/problem_2.py b/problem_2.py new file mode 100644 index 0000000..89fdc1f --- /dev/null +++ b/problem_2.py @@ -0,0 +1,22 @@ +from collections import deque +def hasPath(source,destiantion, maze): + Dir=[(1,0),(0,1),(0,-1),(-1,0)] + q=deque() + q.append((source)) + m,n=len(maze),len(maze[0]) + while(len(q)): + cord=q.popleft() + maze[cord[0]][cord[1]]=2 + + for d in Dir: + i,j=cord[0],cord[1] + while(-1