From 262a300d0d7eedef11f999ac0d2b8bdf0d1762e2 Mon Sep 17 00:00:00 2001 From: "i-dhanyasri.grandhi" Date: Sun, 21 Sep 2025 15:13:53 +0530 Subject: [PATCH] Completed --- Problem1.java | 25 +++++++++++++++++++++++++ Problem2.java | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 Problem1.java create mode 100644 Problem2.java diff --git a/Problem1.java b/Problem1.java new file mode 100644 index 0000000..2a1091f --- /dev/null +++ b/Problem1.java @@ -0,0 +1,25 @@ + +//Time Complexity: O(n) +//Space Complexity: O(n) + +//when we visualize it is a graph problem and the judge will have n-1 indegree and 0 outdegree +//so we can use an array to keep track of the trust count for each person +//if a person trusts someone we decrement their count and if they are trusted by someone we increment their count +//at the end we check if any person has a count of n-1, if yes we return that person's label +//otherwise we return -1 + +class Solution { + public int findJudge(int n, int[][] trust) { + int arr[]=new int[n+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(); + for(int[] dir: dirs){ + int r = dir[0] + curr[0]; + int c = dir[1] + curr[1]; + + while(r>=0 && c>=0 && r