diff --git a/EmployeeImportance.cpp b/EmployeeImportance.cpp new file mode 100644 index 0000000..acd4e47 --- /dev/null +++ b/EmployeeImportance.cpp @@ -0,0 +1,39 @@ +/* +// Definition for Employee. +class Employee { +public: + int id; + int importance; + vector subordinates; +}; +*/ + +class Solution { +public: + int getImportance(vector employees, int id) { + unordered_map> idsMap; + unordered_map usEmp; + vector inorder; + for (int i=0;iid] = employees[i]->subordinates; + usEmp[employees[i]->id] = employees[i]; + } + + queue q; + q.push(id); + int answer = usEmp[id]->importance; + + while (!q.empty()) { + auto node = q.front(); + q.pop(); + + vector direct = idsMap[node]; + for (int i=0;iimportance; + q.push(direct[i]); + } + } + + return answer; + } +}; diff --git a/RottingOranges.cpp b/RottingOranges.cpp new file mode 100644 index 0000000..efe0c07 --- /dev/null +++ b/RottingOranges.cpp @@ -0,0 +1,62 @@ +class Solution { +public: + vector> dirs = {{1,0}, {-1,0}, {0,1}, {0,-1}}; + int orangesRotting(vector>& grid) { + queue> q; + unordered_set us, freshO; + + auto key = [&](int x, int y) { + return to_string(x)+"+"+to_string(y); + }; + + auto markVisited = [&](int x, int y) { + string str = key(x, y); + us.insert(str); + freshO.erase(str); + }; + + auto isSafe = [&](int x, int y) { + if (x >= 0 && y >= 0 && x < grid.size() && y