diff --git a/Problem1.java b/Problem1.java new file mode 100644 index 0000000..93059d6 --- /dev/null +++ b/Problem1.java @@ -0,0 +1,49 @@ +class Problem1 { + int[][] dirs; + int m,n; + + public int orangesRotting(int[][] grid) { + this.dirs = new int[][]{{-1,0},{1,0},{0,1},{0,-1}}; + this.m = grid.length; + this.n = grid[0].length; + int fresh = 0; + + Queue q = new LinkedList<>(); + + for(int i=0; i=0 && c>=0 && r subordinates; +}; +*/ + +class Problem2 { + HashMap map; + + public int getImportance(List employees, int id) { + this.map = new HashMap<>(); + + for(Employee emp: employees){ + map.put(emp.id, emp); + } + + Queue q = new LinkedList<>(); + q.add(id); + + int result = 0; + + while(!q.isEmpty()){ + int currId = q.poll(); + + Employee currObj = map.get(currId); + + result += currObj.importance; + + for(int subId : currObj.subordinates){ + q.add(subId); + } + } + + return result; + } +}