From 2ab0393b90b9325b978af9a5bacdb2e9f90885cc Mon Sep 17 00:00:00 2001 From: akhilsai25 <38877327+akhilsai25@users.noreply.github.com> Date: Sat, 20 Sep 2025 12:45:44 -0500 Subject: [PATCH 1/2] Create TownJudge.java --- TownJudge.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 TownJudge.java diff --git a/TownJudge.java b/TownJudge.java new file mode 100644 index 0000000..5b33d44 --- /dev/null +++ b/TownJudge.java @@ -0,0 +1,20 @@ +// This solution uses an indegree array which will track inward and outward edges to an element. +// For all the inward edges, we increment and outward we decrement +// At the end, if there is any edge with n-1 val then its the judge +class Solution { + public int findJudge(int n, int[][] trust) { + int[] indegree = new int[n]; + Arrays.fill(indegree, 0); + for(int i=0;i Date: Sat, 20 Sep 2025 17:26:17 -0500 Subject: [PATCH 2/2] Create Maze-1.java --- Maze-1.java | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Maze-1.java diff --git a/Maze-1.java b/Maze-1.java new file mode 100644 index 0000000..e5c67b1 --- /dev/null +++ b/Maze-1.java @@ -0,0 +1,34 @@ +// This solution uses a BFS approach to grab the neighbors first +// On each direction of neighbor we roll the ball until valid and add it to the queue +// We change the number to -1 if a column is visited +class Solution { + public boolean hasPath(int[][] maze, int[] start, int[] destination) { + int m = maze.length; + int n = maze[0].length; + Queue queue = new LinkedList(); + + queue.add(start); + maze[start[0]][start[1]]=-1; + int[][] dirs = {{0,1}, {0,-1}, {1,0}, {-1,0}}; + while(!queue.isEmpty()) { + int[] dest = queue.poll(); + + for(int i=0;i=0 && col+dir[1]>=0 && row+dir[0]<=m-1 && col+dir[1]<=n-1) && maze[row+dir[0]][col+dir[1]]!=1) { + row = row+dir[0]; + col = col+dir[1]; + } + if(maze[row][col]!=-1) { + if(row==destination[0] && col==destination[1]) return true; + queue.add(new int[]{row, col}); + maze[row][col]=-1; + } + } + } + + return false; + } +}