Topological Sort Time : O(n) Space : O(n) 1234567891011121314151617181920212223242526272829303132#include <vector>using namespace std;vector<int> topologicalSort(vector<int> jobs, vector<vector<int>> deps) { unordered_map<int, vector<int>> adj; unordered_map<int, int> ind; vector<int> res; queue<int> q; for(auto& dep : deps) { int u = dep[0], v = dep[1]; ind[v]++; adj[u].push_back(v); } for(auto& job : jobs) { if(ind[job] == 0) q.push(job); } while(!q.empty()) { auto u = q.front(); q.pop(); res.push_back(u); for(auto& v : adj[u]) { if(--ind[v] == 0) q.push(v); } } if(res.size() == jobs.size()) return res; return {};}