Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
// Definition for Employee.
class Employee {
public int id;
public int importance;
public List<Integer> subordinates;
};
TC: O(n) whre n is the number of employees
SC: O(n) for the map and the recursive stack
*/



class Solution {
Map<Integer, Employee> map;
int sum;
public int getImportance(List<Employee> 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);
}
}
}
36 changes: 36 additions & 0 deletions RottenOrange.java
Original file line number Diff line number Diff line change
@@ -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<int[]> 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++){

}
}

}
}