From a6a81a1b4be67cd8aad2d9461af6a59f53467a74 Mon Sep 17 00:00:00 2001 From: Praniksha123 Date: Fri, 31 Jul 2026 20:59:52 +0530 Subject: [PATCH] Create graph1.java --- graph1.java | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 graph1.java diff --git a/graph1.java b/graph1.java new file mode 100644 index 0000000..b8374c8 --- /dev/null +++ b/graph1.java @@ -0,0 +1,57 @@ +//problem1 +class Solution { + public int findJudge(int n, int[][] trust) { + int[] arr=new int[n]; + for(int[] t:trust){ + arr[t[0]-1]--; + arr[t[1]-1]++; + } + for(int i=0;i q = new LinkedList<>(); + q.add(new int[]{start[0], start[1]}); + maze[start[0]][start[1]] = -1; + while (!q.isEmpty()) { + int[] curr = q.poll(); + if (curr[0] == destination[0] && + curr[1] == destination[1]) + return true; + for (int[] dir : dirs) { + int r = curr[0] + dir[0]; + int c = curr[1] + dir[1]; + while (r >= 0 && r < m && + c >= 0 && c < n && + maze[r][c] != 1) { + r += dir[0]; + c += dir[1]; + } + r -= dir[0]; + c -= dir[1]; + if (maze[r][c] != -1) { + maze[r][c] = -1; + q.add(new int[]{r, c}); + } + } + } + return false; + } +}