diff --git a/Employee.java b/Employee.java new file mode 100644 index 0000000..38bc721 --- /dev/null +++ b/Employee.java @@ -0,0 +1,34 @@ +/* +// Definition for Employee. +class Employee { + public int id; + public int importance; + public List subordinates; +}; +TC: O(n) whre n is the number of employees +SC: O(n) for the map and the recursive stack +*/ + + + +class Solution { + Map map; + int sum; + public int getImportance(List employees, int id) { + map = new HashMap<>(); + sum = 0; + for(Employee e: employees){ + map.put(e.id, e); + } + dfs(id); + return sum; + } + + private void dfs(int id){ + Employee e = map.get(id); + sum = sum + e.importance; + for(int eid: e.subordinates){ + dfs(eid); + } + } +} \ No newline at end of file diff --git a/RottenOrange.java b/RottenOrange.java new file mode 100644 index 0000000..0efb13d --- /dev/null +++ b/RottenOrange.java @@ -0,0 +1,36 @@ + +/* +Tc: O(m *n) +SC: O(m * n) +m = number of rows and n is number of columns +class Solution { + public int orangesRotting(int[][] grid) { + if(grid.length == 0 || grid[0].length==0){ + return 0; + } + int m = grid.length; + int n = grid[0].length; + Queue q = new LinkedList<>(); + int count = 0; + int level = 0; + int[][] dirs = {{-1,0},{1,0},{0,1},{0,-1}}; + + for(int i = 0; i < m; i++){ + for(int j = 0; j < n; j++){ + if(grid[i][j]== 1){ + count++; + } + else if(grid[i][j] == 2){ + q.add(new int[]{i,j}); + } + } + } + while(!q.isEmpty()){ + int size = q.size(); + for(int i = 0; i < size; i++){ + + } + } + + } +} \ No newline at end of file