diff --git a/employee_imp_690.cpp b/employee_imp_690.cpp new file mode 100644 index 0000000..507bc1d --- /dev/null +++ b/employee_imp_690.cpp @@ -0,0 +1,40 @@ +/* +// Definition for Employee. +class Employee { +public: + int id; + int importance; + vector subordinates; +}; +*/ +//TC: O(m*n) +//SC: O(1) +class Solution { +public: + int getImportance(vector employees, int id) { + queue q; + unordered_map map; + int total=0; + for(auto emp:employees) + { + map[emp->id]=emp; + } + q.push(id); + if(employees.size()==0) + return 0; + while(!q.empty()) + { + auto id=q.front(); q.pop(); + Employee* emp=map[id]; + total+=emp->importance; + if(emp->subordinates.empty()) + continue; + else + { + for(auto e:emp->subordinates) + q.push(e); + } + } + return total; + } +}; diff --git a/rotten_orange_994.cpp b/rotten_orange_994.cpp new file mode 100644 index 0000000..4ea4905 --- /dev/null +++ b/rotten_orange_994.cpp @@ -0,0 +1,57 @@ +class Solution { +public: +//TC: O(m*n) +//SC: O(m*n) +vector> dirs={{-1,0},{1,0},{0,-1},{0,1}}; + + int orangesRotting(vector>& grid) { + queue> q; + int m=grid.size(); + int n=grid[0].size(); + int fresh=0, time=0; + + if(grid.size()==0) + return 0; + for(int i=0;i=0 and newR=0 and newC