id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 2 | {
"code": "class Solution {\npublic:\n int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& inform) {\n vector<int> adj[n];\n for(int i=0;i<manager.size();i++){\n if(manager[i]!=-1){\n adj[manager[i]].push_back(i);\n adj[i].push_back(manager[... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 2 | {
"code": "class Solution {\npublic:\n int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {\n vector<vector<int>> adj(n);\n \n for(int i=0;i<n;i++){\n if(manager[i]!=-1){\n adj[manager[i]].push_back(i);\n }\n }\n ... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 2 | {
"code": "class Solution {\npublic:\n int numOfMinutes(int n, int hD, vector<int>& man, vector<int>& Time) {\n vector<vector<int>> vec(n);\n for(int j = 0; j < man.size(); j++){\n if(man[j] == -1) continue; \n vec[man[j]].push_back(j); \n }\n queue<pair<int, int>... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 2 | {
"code": "class Solution {\npublic:\n int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {\n ios::sync_with_stdio(false);\n cin.tie(NULL);\n cout.tie(NULL);\n vector<list<int>>graph(n,list<int>());\n for(int i=0;i<n;i++){\n if(manager[i... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 2 | {
"code": "class Solution {\n using graph = unordered_map<int, vector<int>>;\n\npublic:\n void findTotalTime(const graph& g, int employee, const vector<int>& informTime, int time, int& totalTime) {\n \n totalTime = max(totalTime, time);\n\n if (g.find(employee) != g.end()) {\n fo... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 2 | {
"code": "class Solution {\npublic:\n void helper(int i,int par, vector<vector<int>>&adj,vector<int>& informTime,int &ans,int t){\n ans=max(t,ans);\n for(int j=0;j<adj[i].size();j++){\n int a=adj[i][j];\n if(a!=par){\n helper(a,i,adj,informTime,ans,t+informTime[i... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 2 | {
"code": "class Solution {\npublic:\n int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& time) {\n unordered_map<int,vector<int>>um;\n for(int i=0;i<manager.size();i++){\n um[manager[i]].push_back(i);\n }\n um.erase(-1);\n queue<int> q;\n q.... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 2 | {
"code": "class Solution {\npublic:\n void DFS(int u, vector<int>& d, vector<vector<int>>& X, vector<int>& informTime)\n {\n for(int v : X[u])\n {\n if (d[v] <= 0)\n {\n d[v] = d[u] + informTime[u];\n DFS(v, d, X, informTime);\n }\n ... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 2 | {
"code": "/*\nBuilding the Adjacency List:\nYou create a map to store each manager and their direct reports.\nBreadth-First Search (BFS):\nYou initialize a queue with the head of the organization and start the time at 0.\nYou process each employee in the queue, updating the time taken to inform them.\nIf an employee... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 2 | {
"code": "class Solution {\npublic:\n int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {\n vector<vector<int>> adjList(n);\n for (int i = 0; i < n; i++) {\n vector<int> v;\n adjList.push_back(v);\n }\n\n for (int i = 0; i < n; i++... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {\n\n vector<vector<int>> adj(manager.size());\n for(int i=0;i<manager.size();i++){\n if(manager[i]!=-1){\n adj[manager[i]].push_back(i);\n adj[i]... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {\n vector<vector<int>>adj(n);\n int mx = 0;\n \n for (int i=0;i<n;i++) {\n if (i == headID) continue;\n adj[manager[i]].push_back(i);\n ... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {\n if(n==1)\n {\n return 0;\n }\n int ans=0;\n vector<vector<int>> adj(n);\n\n for(int i=0;i<manager.size();i++)\n {\n if... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) { \n vector<int> reportees[n];\n for (int i=0; i<n; i++) {\n if (manager[i] != -1) {\n reportees[manager[i]].push_back(i);\n }\n ... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n\n unordered_map<int,int>mpp;\n void dfs(int &node,vector<int>adj[],vector<int>&vis,int mx,int &ans){\n\n vis[node] = 1;\n\n ans = max(ans,mx);\n\n for(auto it:adj[node]){\n if(!vis[it]){\n dfs(it,adj,vis,mx+mpp[node],ans);\n ... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\nprivate:\n void dfs(int node, int& ans, unordered_map<int, list<int>>& adj, int time, vector<int>& informTime) {\n if(adj.find(node) == adj.end()){\n ans = max(time, ans);\n return;\n }\n time += informTime[node];\n\n for (auto i : adj[... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n map<pair<int,int>,int> mp;\n int ans=0;\n vector<int> adj[100001];\n void dfs(int headId,int time){\n if(adj[headId].size()==0){\n ans=max(ans,time);\n return;\n }\n for(int i=0;i<adj[headId].size();i+=1){\n int t... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n map<int, bool> vis;\n int time = 0;\n void dfs(int vertex, vector<pair<int, int>> adj[], int t){\n vis[vertex] = true;\n cout<<vertex<<\" \"<<t<<endl;\n time = max(time , t);\n for(pair<int, int> x : adj[vertex]){\n if(!vis[x.first... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n map<int, bool> vis;\n int time = 0;\n void dfs(int vertex, vector<pair<int, int>> adj[], int t){\n vis[vertex] = true;\n time = max(time , t);\n for(pair<int, int> x : adj[vertex]){\n if(!vis[x.first]){\n dfs(x.first, adj, ... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n int numOfMinutes(int n, int h, vector<int>& m, vector<int>& it) {\n vector<vector<int>>adj(n);\n for(int i =0;i<m.size();i++){ \n if(m[i]==-1)continue;\n adj[i].push_back(m[i]);\n adj[m[i]].push_back(i);\n }\n queue... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n void bfs(vector<vector<int>>adj,int headID,vector<int>&informTime,int& maxTime){\n queue<pair<int,int>>q;\n q.push({headID,0});\n while(!q.empty()){\n auto temp=q.front();\n q.pop();\n int v=temp.first;\n int cu... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\n int getTimeTakenByReportee(unordered_map<int, vector<int>>& managerReporteeMap, vector<int>& informTime, int curr) {\n if (!managerReporteeMap.count(curr)) {\n return 0;\n }\n int timeTakenByReportee = 0;\n for (int i = 0; i < managerReporteeMap[... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n void helper(unordered_map<int,vector<int>> &mp,int head, vector<int> &time, int &maxi, int curr){\n cout<<head<<' ';\n if(time[head]==0){\n maxi= max(maxi,curr);\n return;\n }\n vector<int> arr = mp[head];\n for(int i=0... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\nunordered_map<int, vector<int>> parChild;\nint getMaxHt(int headID,vector<int>& informTime)\n{\n if(parChild.find(headID)== parChild.end())\n {\n return 0;\n }\n vector<int> child = parChild[headID];\n int maxSoFar=0;\n for(auto c:child)\n {\n m... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n int getTime(vector<vector<int>> adj,int src,int n,vector<int> informTime)\n {\n queue<int> q;\n vector<int> visited(n,0);\n q.push(src);\n\n while(!q.empty())\n {\n int node = q.front();\n q.pop();\n\n for... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n\n int f(int manager, vector<int>& informTime, unordered_map<int,vector<int>> &manager_to_manager){\n\n if(manager_to_manager.find(manager) == manager_to_manager.end()) return informTime[manager];\n\n vector<int> mans = manager_to_manager[manager];\n\n int... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n\n int f(int manager, vector<int>& informTime, unordered_map<int,vector<int>> &manager_to_manager){\n\n if(manager_to_manager.find(manager) == manager_to_manager.end()) return informTime[manager];\n\n vector<int> mans = manager_to_manager[manager];\n\n int... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {\n \n unordered_map<int,vector<int>> adj(n); // {manager, {employees}}\n\n for(int i=0 ; i<manager.size() ; i++){\n if(manager[i] != -1)\n ... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {\n vector<vector<int>>v(n);\n for(int i=0;i<n;i++)if(manager[i]!=-1)v[manager[i]].push_back(i);\n queue<vector<int>>q;\n q.push({headID,0});\n int res=0;\n ... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\nint numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {\n if (manager.size() == 1) return 0;\n \n unordered_map<int, vector<int>> report_map;\n \n for (int ii =0; ii < manager.size(); ++ii) {\n if (manager... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {\n unordered_map<int,vector<int>> mp;\n int ans=0,curr_time,node_time,node_val;\n for(int i=0;i<n;i++){\n if(i!=headID)\n mp[manager[i]].push_back(i)... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {\n unordered_map<int,vector<int>> adjlist;\n for(int i=0;i<n;i++){\n int j=manager[i];\n if(j!=-1){\n adjlist[j].push_back(i);\n }\n ... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n // DFS function to compute the total time needed to inform all employees\n int dfs(int emp_id, unordered_map<int, vector<int>>& g, vector<int>& informTime) {\n \n int max_time = 0;\n \n // Traverse all subordinates\n for (int subordinate ... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {\n queue<int> que;\n que.push(headID);\n unordered_set<int> managerSet;\n unordered_map<int, vector<int>> managerVecMap;\n vector<int> informedTimeSum(n);\n ... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n \n int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {\n \n\n unordered_map<int,vector<int>> adj;\n for(int i =0;i<n;i++){\n if(manager[i]==-1)continue;\n adj[manager[i]].push_back(i);\n }\n... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n int numOfMinutes(int n, int head, vector<int>& man, vector<int>& inf) {\n unordered_map<int,vector<int>> sub;\n for(int i=0;i<man.size();i++){\n sub[man[i]].push_back(i);\n }\n\n int ans=0;\n queue<int> que; que.push(head);\n ... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {\n unordered_map<int, vector<int>> manager_to_employees;\n for (int i = 0; i < n; ++i) {\n manager_to_employees[manager[i]].push_back(i);\n }\n\n stack<i... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {\n map<int, vector<int>> v;\n\n for(int i = 0; i < n; i++) {\n if(manager[i] != -1) {\n v[manager[i]].push_back(i);\n }\n }\n \... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {\n \n unordered_map<int,vector<pair<int,int>>> ma;\n for(int i =0;i<n;i++) {\n if(manager[i]!=-1)\n ma[manager[i]].push_back({i, informTime[manager[i... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {\n unordered_map<int,vector<int>> adjlist;\n for(int i=0;i<n;i++){\n int j=manager[i];\n if(j!=-1){\n adjlist[j].push_back(i);\n }\n ... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n // int dfs(int current, unordered_map<int, vector<int>>& graph, vector<int>& informTime, vector<int>& memo){\n // if(memo[current] != -1){\n // return memo[current];\n // }\n\n // int maxt = 0;\n\n // for(int sub : graph[current]){\n ... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {\n \n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n\n unordered_map<int,vector<pair<int,int>>> adj;\n int hea... |
1,492 | <p>A company has <code>n</code> employees with a unique ID for each employee from <code>0</code> to <code>n - 1</code>. The head of the company is the one with <code>headID</code>.</p>
<p>Each employee has one direct manager given in the <code>manager</code> array where <code>manager[i]</code> is the direct manager of... | 3 | {
"code": "class Solution {\npublic:\n int numOfMinutes(int n, int headID, vector<int>& manager, vector<int>& informTime) {\n unordered_map<int,vector<pair<int,int>>> adj;\n int head;\n for(int i=0;i<n;i++)\n {\n if(manager[i]==-1) \n {\n head=i;\n ... |
1,498 | <p>Given two binary trees <code>original</code> and <code>cloned</code> and given a reference to a node <code>target</code> in the original tree.</p>
<p>The <code>cloned</code> tree is a <strong>copy of</strong> the <code>original</code> tree.</p>
<p>Return <em>a reference to the same node</em> in the <code>cloned</c... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\n\nclass Solution {\npublic:\n TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNod... |
1,498 | <p>Given two binary trees <code>original</code> and <code>cloned</code> and given a reference to a node <code>target</code> in the original tree.</p>
<p>The <code>cloned</code> tree is a <strong>copy of</strong> the <code>original</code> tree.</p>
<p>Return <em>a reference to the same node</em> in the <code>cloned</c... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\n\nclass Solution {\npublic:\n TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNod... |
1,498 | <p>Given two binary trees <code>original</code> and <code>cloned</code> and given a reference to a node <code>target</code> in the original tree.</p>
<p>The <code>cloned</code> tree is a <strong>copy of</strong> the <code>original</code> tree.</p>
<p>Return <em>a reference to the same node</em> in the <code>cloned</c... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\n\nclass Solution {\npublic:\n TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNod... |
1,498 | <p>Given two binary trees <code>original</code> and <code>cloned</code> and given a reference to a node <code>target</code> in the original tree.</p>
<p>The <code>cloned</code> tree is a <strong>copy of</strong> the <code>original</code> tree.</p>
<p>Return <em>a reference to the same node</em> in the <code>cloned</c... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\n\nclass Solution {\npublic:\n TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNod... |
1,498 | <p>Given two binary trees <code>original</code> and <code>cloned</code> and given a reference to a node <code>target</code> in the original tree.</p>
<p>The <code>cloned</code> tree is a <strong>copy of</strong> the <code>original</code> tree.</p>
<p>Return <em>a reference to the same node</em> in the <code>cloned</c... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\n\nclass Solution {\npublic:\n TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNod... |
1,498 | <p>Given two binary trees <code>original</code> and <code>cloned</code> and given a reference to a node <code>target</code> in the original tree.</p>
<p>The <code>cloned</code> tree is a <strong>copy of</strong> the <code>original</code> tree.</p>
<p>Return <em>a reference to the same node</em> in the <code>cloned</c... | 0 | {
"code": "#pragma GCC target(\"avx, mmx, sse2, sse3, sse4\")\nauto _ = []() noexcept\n{\n std::ios::sync_with_stdio(false);\n std::cin.tie(nullptr);\n std::cout.tie(nullptr);\n return 0;\n}();\n\ntypedef struct TreeNode NodeBT_t;\n\nclass Solution final\n{\npublic:\n NodeBT_t* getTargetCopy(const Node... |
1,498 | <p>Given two binary trees <code>original</code> and <code>cloned</code> and given a reference to a node <code>target</code> in the original tree.</p>
<p>The <code>cloned</code> tree is a <strong>copy of</strong> the <code>original</code> tree.</p>
<p>Return <em>a reference to the same node</em> in the <code>cloned</c... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\nclass Solution {\npublic:\n TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNode*... |
1,498 | <p>Given two binary trees <code>original</code> and <code>cloned</code> and given a reference to a node <code>target</code> in the original tree.</p>
<p>The <code>cloned</code> tree is a <strong>copy of</strong> the <code>original</code> tree.</p>
<p>Return <em>a reference to the same node</em> in the <code>cloned</c... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\n\nclass Solution {\npublic:\n TreeNode* solve(TreeNode* root,TreeNode* target)\n {\n if(ro... |
1,498 | <p>Given two binary trees <code>original</code> and <code>cloned</code> and given a reference to a node <code>target</code> in the original tree.</p>
<p>The <code>cloned</code> tree is a <strong>copy of</strong> the <code>original</code> tree.</p>
<p>Return <em>a reference to the same node</em> in the <code>cloned</c... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\n\nclass Solution {\npublic:\n TreeNode * ans ;\n void inorder(TreeNode *temp,TreeNode*org,TreeNo... |
1,498 | <p>Given two binary trees <code>original</code> and <code>cloned</code> and given a reference to a node <code>target</code> in the original tree.</p>
<p>The <code>cloned</code> tree is a <strong>copy of</strong> the <code>original</code> tree.</p>
<p>Return <em>a reference to the same node</em> in the <code>cloned</c... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\n\nclass Solution {\npublic:\n TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNod... |
1,498 | <p>Given two binary trees <code>original</code> and <code>cloned</code> and given a reference to a node <code>target</code> in the original tree.</p>
<p>The <code>cloned</code> tree is a <strong>copy of</strong> the <code>original</code> tree.</p>
<p>Return <em>a reference to the same node</em> in the <code>cloned</c... | 2 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\n\nclass Solution {\npublic:\n TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNod... |
1,498 | <p>Given two binary trees <code>original</code> and <code>cloned</code> and given a reference to a node <code>target</code> in the original tree.</p>
<p>The <code>cloned</code> tree is a <strong>copy of</strong> the <code>original</code> tree.</p>
<p>Return <em>a reference to the same node</em> in the <code>cloned</c... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\n\nclass Solution {\npublic:\n TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNod... |
1,498 | <p>Given two binary trees <code>original</code> and <code>cloned</code> and given a reference to a node <code>target</code> in the original tree.</p>
<p>The <code>cloned</code> tree is a <strong>copy of</strong> the <code>original</code> tree.</p>
<p>Return <em>a reference to the same node</em> in the <code>cloned</c... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\n\nclass Solution {\npublic:\n TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNod... |
1,498 | <p>Given two binary trees <code>original</code> and <code>cloned</code> and given a reference to a node <code>target</code> in the original tree.</p>
<p>The <code>cloned</code> tree is a <strong>copy of</strong> the <code>original</code> tree.</p>
<p>Return <em>a reference to the same node</em> in the <code>cloned</c... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\n\nclass Solution {\npublic:\n TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNod... |
1,498 | <p>Given two binary trees <code>original</code> and <code>cloned</code> and given a reference to a node <code>target</code> in the original tree.</p>
<p>The <code>cloned</code> tree is a <strong>copy of</strong> the <code>original</code> tree.</p>
<p>Return <em>a reference to the same node</em> in the <code>cloned</c... | 3 | {
"code": "class Solution {\npublic:\n TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNode* target) {\n\n queue<TreeNode *> q;\n q.push(cloned);\n while(!q.empty())\n {\n TreeNode * node = q.front();\n q.pop();\n if(node->val == target... |
1,498 | <p>Given two binary trees <code>original</code> and <code>cloned</code> and given a reference to a node <code>target</code> in the original tree.</p>
<p>The <code>cloned</code> tree is a <strong>copy of</strong> the <code>original</code> tree.</p>
<p>Return <em>a reference to the same node</em> in the <code>cloned</c... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\n\nclass Solution {\npublic:\n TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNod... |
1,498 | <p>Given two binary trees <code>original</code> and <code>cloned</code> and given a reference to a node <code>target</code> in the original tree.</p>
<p>The <code>cloned</code> tree is a <strong>copy of</strong> the <code>original</code> tree.</p>
<p>Return <em>a reference to the same node</em> in the <code>cloned</c... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\n\nclass Solution {\npublic:\n TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNod... |
1,498 | <p>Given two binary trees <code>original</code> and <code>cloned</code> and given a reference to a node <code>target</code> in the original tree.</p>
<p>The <code>cloned</code> tree is a <strong>copy of</strong> the <code>original</code> tree.</p>
<p>Return <em>a reference to the same node</em> in the <code>cloned</c... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\n\nclass Solution {\npublic:\n TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNod... |
1,498 | <p>Given two binary trees <code>original</code> and <code>cloned</code> and given a reference to a node <code>target</code> in the original tree.</p>
<p>The <code>cloned</code> tree is a <strong>copy of</strong> the <code>original</code> tree.</p>
<p>Return <em>a reference to the same node</em> in the <code>cloned</c... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\n\nclass Solution {\npublic:\n TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNod... |
1,498 | <p>Given two binary trees <code>original</code> and <code>cloned</code> and given a reference to a node <code>target</code> in the original tree.</p>
<p>The <code>cloned</code> tree is a <strong>copy of</strong> the <code>original</code> tree.</p>
<p>Return <em>a reference to the same node</em> in the <code>cloned</c... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\n\nclass Solution {\npublic:\n TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNod... |
1,498 | <p>Given two binary trees <code>original</code> and <code>cloned</code> and given a reference to a node <code>target</code> in the original tree.</p>
<p>The <code>cloned</code> tree is a <strong>copy of</strong> the <code>original</code> tree.</p>
<p>Return <em>a reference to the same node</em> in the <code>cloned</c... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\n\nclass Solution {\npublic:\n TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNod... |
1,498 | <p>Given two binary trees <code>original</code> and <code>cloned</code> and given a reference to a node <code>target</code> in the original tree.</p>
<p>The <code>cloned</code> tree is a <strong>copy of</strong> the <code>original</code> tree.</p>
<p>Return <em>a reference to the same node</em> in the <code>cloned</c... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\n\nclass Solution {\npublic:\n TreeNode* getTargetCopy(TreeNode* original, TreeNode* cloned, TreeNod... |
1,496 | <p>Given an <code>m x n</code> matrix of <strong>distinct </strong>numbers, return <em>all <strong>lucky numbers</strong> in the matrix in <strong>any </strong>order</em>.</p>
<p>A <strong>lucky number</strong> is an element of the matrix such that it is the minimum element in its row and maximum in its column.</p>
<... | 0 | {
"code": "class Solution {\npublic:\n vector<int> luckyNumbers (vector<vector<int>>& matrix) {\n int rows = matrix.size();\n int cols = matrix[0].size();\n\n int row_maximum_of_minimums = 0;\n for (const auto& row : matrix) {\n row_maximum_of_minimums = max(*min_element(row.... |
1,496 | <p>Given an <code>m x n</code> matrix of <strong>distinct </strong>numbers, return <em>all <strong>lucky numbers</strong> in the matrix in <strong>any </strong>order</em>.</p>
<p>A <strong>lucky number</strong> is an element of the matrix such that it is the minimum element in its row and maximum in its column.</p>
<... | 0 | {
"code": "class Solution {\npublic:\n vector<int> luckyNumbers (vector<vector<int>>& matrix) {\n vector<int>ans;\n for(int i=0;i<matrix.size();i++)\n {\n int mn=INT_MAX;\n int ind=-1;\n for(int j=0;j<matrix[i].size();j++)\n {\n if(mn>... |
1,496 | <p>Given an <code>m x n</code> matrix of <strong>distinct </strong>numbers, return <em>all <strong>lucky numbers</strong> in the matrix in <strong>any </strong>order</em>.</p>
<p>A <strong>lucky number</strong> is an element of the matrix such that it is the minimum element in its row and maximum in its column.</p>
<... | 0 | {
"code": "class Solution {\npublic:\n vector<int> luckyNumbers(vector<vector<int>>& matrix) {\n int row=matrix.size();\n int col=matrix[0].size();\n int min=0;\n int max=0;\n int i_row=0;\n int j_col=0;\n vector<int>vec;\n for(int i=0;i<row;i++){\n ... |
1,496 | <p>Given an <code>m x n</code> matrix of <strong>distinct </strong>numbers, return <em>all <strong>lucky numbers</strong> in the matrix in <strong>any </strong>order</em>.</p>
<p>A <strong>lucky number</strong> is an element of the matrix such that it is the minimum element in its row and maximum in its column.</p>
<... | 0 | {
"code": "class Solution {\npublic:\n bool check(vector<vector<int>>& matrix,int row,int col,int p){\n for(int i=0;i<matrix.size();i++){\n if(matrix[i][col]>p){\n return false;\n }\n }\n return true;\n }\n vector<int> luckyNumbers(vector<vector<int>>& matrix) {\n ... |
1,496 | <p>Given an <code>m x n</code> matrix of <strong>distinct </strong>numbers, return <em>all <strong>lucky numbers</strong> in the matrix in <strong>any </strong>order</em>.</p>
<p>A <strong>lucky number</strong> is an element of the matrix such that it is the minimum element in its row and maximum in its column.</p>
<... | 0 | {
"code": "class Solution {\npublic:\n bool check(vector<vector<int>>& matrix, int row, int col, int p) {\n for (int i = 0; i < matrix.size(); i++) {\n if (matrix[i][col] > p) {\n return false;\n }\n }\n return true;\n }\n vector<int> luckyNumbers(vec... |
1,496 | <p>Given an <code>m x n</code> matrix of <strong>distinct </strong>numbers, return <em>all <strong>lucky numbers</strong> in the matrix in <strong>any </strong>order</em>.</p>
<p>A <strong>lucky number</strong> is an element of the matrix such that it is the minimum element in its row and maximum in its column.</p>
<... | 0 | {
"code": "class Solution {\npublic:\n vector<int> luckyNumbers(vector<vector<int>>& matrix) {\n std::vector<int> result;\n std::vector<int> min_el_pos = {0,0};\n std::vector<int> max_el_pos = {0,0};\n \n for (int k = 0; k < matrix.size(); k++){\n min_el_pos[0] = k;\n ... |
1,496 | <p>Given an <code>m x n</code> matrix of <strong>distinct </strong>numbers, return <em>all <strong>lucky numbers</strong> in the matrix in <strong>any </strong>order</em>.</p>
<p>A <strong>lucky number</strong> is an element of the matrix such that it is the minimum element in its row and maximum in its column.</p>
<... | 0 | {
"code": "class Solution {\npublic:\n vector<int> luckyNumbers(vector<vector<int>>& matrix) {\n vector<int> luckyNumbers;\n for (int i = 0; i < matrix.size(); i++) {\n int minVal = matrix[i][0]; \n int minIndex = 0; \n for (int j = 1; j < matrix[i].size(); j++) {\n ... |
1,496 | <p>Given an <code>m x n</code> matrix of <strong>distinct </strong>numbers, return <em>all <strong>lucky numbers</strong> in the matrix in <strong>any </strong>order</em>.</p>
<p>A <strong>lucky number</strong> is an element of the matrix such that it is the minimum element in its row and maximum in its column.</p>
<... | 1 | {
"code": "class Solution {\npublic:\n vector<int> luckyNumbers(vector<vector<int>>& matrix) {\n int m = matrix.size();\n int n = matrix[0].size();\n vector<int> minOfRows(m);\n \n for(int i = 0; i < m; ++i) {\n int minEle = INT_MAX;\n int minInd = -1;\n ... |
1,496 | <p>Given an <code>m x n</code> matrix of <strong>distinct </strong>numbers, return <em>all <strong>lucky numbers</strong> in the matrix in <strong>any </strong>order</em>.</p>
<p>A <strong>lucky number</strong> is an element of the matrix such that it is the minimum element in its row and maximum in its column.</p>
<... | 1 | {
"code": "class Solution {\npublic:\n static vector<int> luckyNumbers (vector<vector<int>>& matrix) {\n const int m=matrix.size(), n=matrix[0].size();\n int max_rmin=INT_MIN, posj=-1;\n for(int i=0; i<m; i++){\n int p=min_element(matrix[i].begin(), matrix[i].end())-matrix[i].begin(... |
1,496 | <p>Given an <code>m x n</code> matrix of <strong>distinct </strong>numbers, return <em>all <strong>lucky numbers</strong> in the matrix in <strong>any </strong>order</em>.</p>
<p>A <strong>lucky number</strong> is an element of the matrix such that it is the minimum element in its row and maximum in its column.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n vector<int> luckyNumbers(vector<vector<int>>& matrix) {\n int m = matrix.size(), n = matrix[0].size();\n vector<int> row(m), col(n);\n col = matrix[0];\n for(int i = 0; i < m; i++)\n row[i] = *min_element(matrix[i].begin(), matrix[i].end... |
1,496 | <p>Given an <code>m x n</code> matrix of <strong>distinct </strong>numbers, return <em>all <strong>lucky numbers</strong> in the matrix in <strong>any </strong>order</em>.</p>
<p>A <strong>lucky number</strong> is an element of the matrix such that it is the minimum element in its row and maximum in its column.</p>
<... | 2 | {
"code": "class Solution {\npublic:\n vector<int> luckyNumbers(vector<vector<int>>& matrix) {\n set<int> minRow;\n vector<int> result;\n for (int i = 0; i < matrix.size(); i++) {\n auto it = min_element(matrix[i].begin(), matrix[i].end());\n minRow.insert(*it);\n ... |
1,496 | <p>Given an <code>m x n</code> matrix of <strong>distinct </strong>numbers, return <em>all <strong>lucky numbers</strong> in the matrix in <strong>any </strong>order</em>.</p>
<p>A <strong>lucky number</strong> is an element of the matrix such that it is the minimum element in its row and maximum in its column.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<int> luckyNumbers (vector<vector<int>>& matrix) {\n vector<int> res;\n int m = matrix.size(), n = matrix[0].size();\n\n // 找出每一行的最小值\n vector<int> minRow(m);\n for (int i = 0; i < m; ++i) {\n minRow[i] = *min_element(matrix... |
1,496 | <p>Given an <code>m x n</code> matrix of <strong>distinct </strong>numbers, return <em>all <strong>lucky numbers</strong> in the matrix in <strong>any </strong>order</em>.</p>
<p>A <strong>lucky number</strong> is an element of the matrix such that it is the minimum element in its row and maximum in its column.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<int> luckyNumbers (vector<vector<int>>& matrix) {\n int rows = matrix.size();\n int cols = matrix[0].size();\n \n vector<int> row_minimums(rows, INT_MAX);\n vector<int> col_maximums(cols, 0);\n \n for (int row_ind = 0; r... |
1,496 | <p>Given an <code>m x n</code> matrix of <strong>distinct </strong>numbers, return <em>all <strong>lucky numbers</strong> in the matrix in <strong>any </strong>order</em>.</p>
<p>A <strong>lucky number</strong> is an element of the matrix such that it is the minimum element in its row and maximum in its column.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<int> luckyNumbers (vector<vector<int>>& matrix) {\n ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0); // Speed up I/O operations\n vector<int> res; // Vector to store the result\n unordered_map<int,int> row; // Map to store minimum elemen... |
1,496 | <p>Given an <code>m x n</code> matrix of <strong>distinct </strong>numbers, return <em>all <strong>lucky numbers</strong> in the matrix in <strong>any </strong>order</em>.</p>
<p>A <strong>lucky number</strong> is an element of the matrix such that it is the minimum element in its row and maximum in its column.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<int> luckyNumbers(vector<vector<int>>& matrix) \n {\n vector<int> oVec;\n unordered_set<int> iSet;\n for(int j = 0; j < matrix[0].size(); ++j)\n {\n int temp = 0;\n for(int i = 0; i < matrix.size(); ++i)\n ... |
1,496 | <p>Given an <code>m x n</code> matrix of <strong>distinct </strong>numbers, return <em>all <strong>lucky numbers</strong> in the matrix in <strong>any </strong>order</em>.</p>
<p>A <strong>lucky number</strong> is an element of the matrix such that it is the minimum element in its row and maximum in its column.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<int> luckyNumbers(vector<vector<int>>& arr) {\n vector<int>col,row;\n for(int i=0;i<arr.size();i++){\n int min1=INT_MAX;\n int max1=INT_MIN;\n for(int j=0;j<arr[i].size();j++){\n if(arr[i][j]<min1){\n ... |
1,496 | <p>Given an <code>m x n</code> matrix of <strong>distinct </strong>numbers, return <em>all <strong>lucky numbers</strong> in the matrix in <strong>any </strong>order</em>.</p>
<p>A <strong>lucky number</strong> is an element of the matrix such that it is the minimum element in its row and maximum in its column.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<int> luckyNumbers (vector<vector<int>>& matrix) \n {\n vector<int> ans;\n int n = matrix.size();\n int m = matrix[0].size();\n unordered_set<int> row_vec;\n unordered_set<int> col_vec;\n\n for (int i = 0; i < n; i++) \n ... |
1,496 | <p>Given an <code>m x n</code> matrix of <strong>distinct </strong>numbers, return <em>all <strong>lucky numbers</strong> in the matrix in <strong>any </strong>order</em>.</p>
<p>A <strong>lucky number</strong> is an element of the matrix such that it is the minimum element in its row and maximum in its column.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<int> luckyNumbers (vector<vector<int>>& matrix) \n {\n vector<int> ans;\n int n = matrix.size();\n int m = matrix[0].size();\n unordered_set<int> row_vec;\n unordered_set<int> col_vec;\n\n for (int i = 0; i < n; i++) \n ... |
1,496 | <p>Given an <code>m x n</code> matrix of <strong>distinct </strong>numbers, return <em>all <strong>lucky numbers</strong> in the matrix in <strong>any </strong>order</em>.</p>
<p>A <strong>lucky number</strong> is an element of the matrix such that it is the minimum element in its row and maximum in its column.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<int> luckyNumbers(vector<vector<int>>& matrix) {\n map<int,int>mp1;\n int n=matrix.size();\n int m=matrix[0].size();\n for(int i=0;i<n;i++){\n int mini=INT_MAX;\n for(int j=0;j<m;j++){\n if(matrix[i][j]<m... |
1,496 | <p>Given an <code>m x n</code> matrix of <strong>distinct </strong>numbers, return <em>all <strong>lucky numbers</strong> in the matrix in <strong>any </strong>order</em>.</p>
<p>A <strong>lucky number</strong> is an element of the matrix such that it is the minimum element in its row and maximum in its column.</p>
<... | 3 | {
"code": "class Solution {\npublic:\n vector<int> luckyNumbers(vector<vector<int>>& matrix) {\n map<int,int> ma;\n int m = matrix.size();\n int n = matrix[0].size();\n for(int i=0; i<m; i++) {\n int currMin = INT_MAX;\n for(int j=0; j<n; j++) {\n if... |
1,285 | <p>Given the <code>root</code> of a binary search tree, return <em>a <strong>balanced</strong> binary search tree with the same node values</em>. If there is more than one answer, return <strong>any of them</strong>.</p>
<p>A binary search tree is <strong>balanced</strong> if the depth of the two subtrees of every nod... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,285 | <p>Given the <code>root</code> of a binary search tree, return <em>a <strong>balanced</strong> binary search tree with the same node values</em>. If there is more than one answer, return <strong>any of them</strong>.</p>
<p>A binary search tree is <strong>balanced</strong> if the depth of the two subtrees of every nod... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,285 | <p>Given the <code>root</code> of a binary search tree, return <em>a <strong>balanced</strong> binary search tree with the same node values</em>. If there is more than one answer, return <strong>any of them</strong>.</p>
<p>A binary search tree is <strong>balanced</strong> if the depth of the two subtrees of every nod... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,285 | <p>Given the <code>root</code> of a binary search tree, return <em>a <strong>balanced</strong> binary search tree with the same node values</em>. If there is more than one answer, return <strong>any of them</strong>.</p>
<p>A binary search tree is <strong>balanced</strong> if the depth of the two subtrees of every nod... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,285 | <p>Given the <code>root</code> of a binary search tree, return <em>a <strong>balanced</strong> binary search tree with the same node values</em>. If there is more than one answer, return <strong>any of them</strong>.</p>
<p>A binary search tree is <strong>balanced</strong> if the depth of the two subtrees of every nod... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,285 | <p>Given the <code>root</code> of a binary search tree, return <em>a <strong>balanced</strong> binary search tree with the same node values</em>. If there is more than one answer, return <strong>any of them</strong>.</p>
<p>A binary search tree is <strong>balanced</strong> if the depth of the two subtrees of every nod... | 0 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,285 | <p>Given the <code>root</code> of a binary search tree, return <em>a <strong>balanced</strong> binary search tree with the same node values</em>. If there is more than one answer, return <strong>any of them</strong>.</p>
<p>A binary search tree is <strong>balanced</strong> if the depth of the two subtrees of every nod... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,285 | <p>Given the <code>root</code> of a binary search tree, return <em>a <strong>balanced</strong> binary search tree with the same node values</em>. If there is more than one answer, return <strong>any of them</strong>.</p>
<p>A binary search tree is <strong>balanced</strong> if the depth of the two subtrees of every nod... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,285 | <p>Given the <code>root</code> of a binary search tree, return <em>a <strong>balanced</strong> binary search tree with the same node values</em>. If there is more than one answer, return <strong>any of them</strong>.</p>
<p>A binary search tree is <strong>balanced</strong> if the depth of the two subtrees of every nod... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,285 | <p>Given the <code>root</code> of a binary search tree, return <em>a <strong>balanced</strong> binary search tree with the same node values</em>. If there is more than one answer, return <strong>any of them</strong>.</p>
<p>A binary search tree is <strong>balanced</strong> if the depth of the two subtrees of every nod... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,285 | <p>Given the <code>root</code> of a binary search tree, return <em>a <strong>balanced</strong> binary search tree with the same node values</em>. If there is more than one answer, return <strong>any of them</strong>.</p>
<p>A binary search tree is <strong>balanced</strong> if the depth of the two subtrees of every nod... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,285 | <p>Given the <code>root</code> of a binary search tree, return <em>a <strong>balanced</strong> binary search tree with the same node values</em>. If there is more than one answer, return <strong>any of them</strong>.</p>
<p>A binary search tree is <strong>balanced</strong> if the depth of the two subtrees of every nod... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,285 | <p>Given the <code>root</code> of a binary search tree, return <em>a <strong>balanced</strong> binary search tree with the same node values</em>. If there is more than one answer, return <strong>any of them</strong>.</p>
<p>A binary search tree is <strong>balanced</strong> if the depth of the two subtrees of every nod... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,285 | <p>Given the <code>root</code> of a binary search tree, return <em>a <strong>balanced</strong> binary search tree with the same node values</em>. If there is more than one answer, return <strong>any of them</strong>.</p>
<p>A binary search tree is <strong>balanced</strong> if the depth of the two subtrees of every nod... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
1,285 | <p>Given the <code>root</code> of a binary search tree, return <em>a <strong>balanced</strong> binary search tree with the same node values</em>. If there is more than one answer, return <strong>any of them</strong>.</p>
<p>A binary search tree is <strong>balanced</strong> if the depth of the two subtrees of every nod... | 3 | {
"code": "/**\n * Definition for a binary tree node.\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode() : val(0), left(nullptr), right(nullptr) {}\n * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n * TreeNode(int x, TreeNode *left, TreeNod... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.