id int64 1 3.58k | problem_description stringlengths 516 21.8k | instruction int64 0 3 | solution_c dict |
|---|---|---|---|
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution {\n unordered_map<int, vector<int>> edges;\n unordered_set<int> visited;\n vector<int> path;\n\n void dfs(int n, auto f) {\n visited.insert(n);\n path.push_back(n);\n for (auto child : edges[n]) {\n if (!visited.count(child))\n dfs(c... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution {\n using Graph = vector<unordered_set<int>>;\n Graph graph;\npublic:\n vector<int> findMinHeightTrees(int n, vector<vector<int>>& edges) {\n graph = Graph(n);\n for(const auto& e : edges) {\n graph[e[0]].insert(e[1]);\n graph[e[1]].insert(e[0]);\... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution {\npublic:\n\n vector<int> findMinHeightTrees(int n, vector<vector<int>>& edges) {\n if (n == 1) return {0};\n\n vector<unordered_set<int>> adj(n);\n\n for (auto& e : edges) {\n adj[e[0]].insert(e[1]);\n adj[e[1]].insert(e[0]);\n } \n\n ... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution {\n using Graph = vector<unordered_set<int>>;\n Graph graph;\npublic:\n vector<int> findMinHeightTrees(int n, vector<vector<int>>& edges) {\n graph = Graph(n);\n for(const auto& e : edges) {\n graph[e[0]].insert(e[1]);\n graph[e[1]].insert(e[0]);\... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "// Approach 1: Topological Sorting\nclass Solution {\npublic:\n vector<int> findMinHeightTrees(int n, vector<vector<int>>& edges) {\n // edge cases\n if(n < 2) {\n vector<int> centroids;\n for(int i = 0; i < n; i++) {\n centroids.push_back(i);\n ... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution {\npublic:\n\n\n // vector<int> findMinHeightTrees(int n, vector<vector<int>>& edges) {\n // // unordered_map<int, vector<int>> links;\n // vector<vector<int>> graph (n, vector<int>());\n // vector<int> degree (n, 0);\n\n // int remainingGraph = n;\n\n // ... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution {\npublic:\n\n\n // vector<int> findMinHeightTrees(int n, vector<vector<int>>& edges) {\n // // unordered_map<int, vector<int>> links;\n // vector<vector<int>> graph (n, vector<int>());\n // vector<int> degree (n, 0);\n\n // int remainingGraph = n;\n\n // ... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution {\npublic:\n\n // int calculateHeight(unordered_map<int, vector<int>>& graph, int n,int min_ind){\n // queue<int> start;\n // vector<int>visit(n,0);\n // start.push(min_ind);\n // int level=0;\n // while(!start.empty()){\n // int size=start.si... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findMinHeightTrees(int n, vector<vector<int>>& edges) {\n ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);\n if (n == 1) return {0};\n\n vector<unordered_set<int>> adj(n);\n for (const auto &edge : edges) {\n adj[edge[0]].in... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findMinHeightTrees(int n, vector<vector<int>>& edge) {\n if (n==1) return {0};\n if (n==2) return {0,1};\n std::unordered_map<int, std::vector<int>> tree;\n std::vector<int> d(n), ans;\n for (auto& e: edge) {\n tree[e[... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findMinHeightTrees(int n, vector<vector<int>>& edges) {\n if(n==1) return {0};\n\n unordered_map<int, vector<int>> adj;\n\n for(vector<int> v: edges){\n adj[v[0]].push_back(v[1]);\n adj[v[1]].push_back(v[0]);\n }\n... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution {\n vector<set<int>> buildGraph(int n, vector<vector<int>>& edges) {\n vector<set<int>> graph(n, set<int>());\n for(auto edge: edges) {\n graph[edge[0]].insert(edge[1]);\n graph[edge[1]].insert(edge[0]);\n }\n return graph;\n }\npublic:... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution {\npublic:\n vector<int> dfs( unordered_map<int,vector<int>>&graph, int root, int pa ){\n vector<int> ret={0,root}; //[distance, node]\n for(auto v : graph[root]){\n if( v == pa) continue;\n vector<int> p= dfs(graph,v,root);\n int dist = p[0]... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findMinHeightTrees(int n, vector<vector<int>>& edges) {\n vector<unordered_set<int>> graph(n);\n for(vector<int> v : edges){\n graph[v[0]].insert(v[1]);\n graph[v[1]].insert(v[0]);\n }\n if(n == 1){\n re... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class MyGraphNode {\npublic:\nint val;\nvector<int> neighbours;\n MyGraphNode(int val) {\n this->val = val;\n }\n};\n\nclass Solution {\nunordered_map<int, MyGraphNode*> graph;\nunordered_map<int, bool> visited;\n\nprivate:\n int bfsFurthestNode(int n) {\n visited.clear();\n q... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution1 {\npublic:\n vector<int> findMinHeightTrees(int n, vector<vector<int>>& edges) {\n return {};\n }\n};\n\nclass Solution {\npublic:\nvector<int> findMinHeightTrees(int n, vector<vector<int> >& edges) {\nif (n == 1) return {0};\nvector<int> res;\nvector<unordered_set<int>> adj(n)... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findMinHeightTrees(int n, vector<vector<int>>& edges) {\n map<int,vector<int>>adj; \n map<int,int>nb_cnt;\n for(auto &i:edges)\n {\n nb_cnt[i[0]]++;\n nb_cnt[i[1]]++;\n\n adj[i[0]].push_back(i[1]);\n ... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "\nclass Solution0 {\npublic:\n // Function to find the nodes that form trees with the minimum height\n vector<int> findMinHeightTrees(int numNodes, vector<vector<int>>& edges) {\n // Base case: if there's only one node, it's the root of a minHeightTree\n if (numNodes == 1) return {0};\n... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findMinHeightTrees(int n, vector<vector<int>>& edges) {\n /*Idea is find the nodes from which all leaves are close\n and these nodes as root will be provides us minHeightTree\n if # of nodes are even we hca have atmost 2 such nodes as root... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findMinHeightTrees(int n, vector<vector<int>>& edges) {\n if(n < 2){\n vector<int> res;\n for(int i = 0; i < n; i++){\n res.push_back(i);\n }\n return res;\n }\n vector<unordered_set<i... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findMinHeightTrees(int n, vector<vector<int>>& edges) {\n if (n == 1) {\n vector<int> tmp({0});\n return tmp;\n }\n if (n == 2) {\n return edges[0];\n }\n unordered_map<int, set<int>> treeMap;\n ... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution {\npublic:\n\n vector<int> dfs(int u, int p, vector<int> adj[], vector<vector<int>> &h){\n int mx1=0, mx2=0;\n for(auto e:adj[u]){\n if(e==p) continue;\n int hc=1+dfs(e,u,adj,h)[0];\n if(hc>mx2){\n swap(hc,mx2);\n ... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findMinHeightTrees(int n, vector<vector<int>>& edges) {\n if (edges.empty()) {\n return {0};\n }\n\n unordered_map<int, set<int>> edges_map;\n vector<int> incoming_edges(n);\n int num_edges = 0;\n for (vector<in... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findMinHeightTrees(int n, vector<vector<int>>& edges) {\n\n if (n == 1) {\n return {0};\n }\n\n //The MHT will always be at the centre of the graph. The approach is to keep trimming leaves until we are left with 1 or 2 nodes left\n ... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findMinHeightTrees(int n, vector<vector<int>>& edge) {\n if (n <=1) {\n return {0};\n }\n unordered_map<int, unordered_set<int>> adj;\n for(int i = 0;i<edge.size();i++) {\n adj[edge[i][0]].insert(edge[i][1]);\n ... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "#include <vector>\n#include <unordered_map>\n#include <unordered_set>\n#include <queue>\n\nclass Solution {\npublic:\n std::vector<int> findMinHeightTrees(int n, std::vector<std::vector<int>>& edges) {\n if (n == 1) return {0}; // A single node is always a root of MHT\n if (n == 2) return ... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Node {\npublic:\n int val;\n unordered_set<Node*> neighbor;\n Node(int v) : val(v) {};\n};\n\nclass Solution {\npublic:\n vector<int> findMinHeightTrees(int n, vector<vector<int>>& edges) {\n // onion peeling, the left 1 or 2 are the result\n // peeling: start from leaves, o... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findMinHeightTrees(int n, vector<vector<int>>& edges) {\n if (n == 1)\n return {0};\n // prune all node with only 1 edge, repeat this until there are 1 or 2 nodes remaining.\n vector<int> numEdges (n, 0);\n // node idx -> inv... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution {\npublic:\n unordered_map<int, vector<int>> graph(vector<vector<int>>& edges) {\n unordered_map<int, vector<int>> m;\n for (auto& e : edges) {\n m[e[0]].push_back(e[1]);\n m[e[1]].push_back(e[0]);\n }\n return m;\n }\n\n vector<int>... |
310 | <p>A tree is an undirected graph in which any two vertices are connected by <i>exactly</i> one path. In other words, any connected graph without simple cycles is a tree.</p>
<p>Given a tree of <code>n</code> nodes labelled from <code>0</code> to <code>n - 1</code>, and an array of <code>n - 1</code... | 3 | {
"code": "class Solution {\npublic:\n vector<int> findMinHeightTrees(int n, vector<vector<int>>& edges) {\n if(n == 1 || n == 0)\n return {0};\n \n unordered_map<int, unordered_set<int>> graph;\n for(auto & edge : edges)\n {\n graph[edge[0]].insert(edge[1])... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 0 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n // {distance , {i , j}}\n priority_queue<pair<int,pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>> pq;\n \n pq.push({0,{entrance[0], entra... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 0 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n // {distance , {i , j}}\n priority_queue<pair<int,pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>> pq;\n \n pq.push({0,{entrance[0], entra... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 0 | {
"code": "class Solution {\nstruct Position {\n uint8_t row;\n uint8_t col;\n Position(uint8_t r, uint8_t c)\n : row(r), col(c) {}\n};\npublic:\nint nearestExit(std::vector<std::vector<char>>& maze, std::vector<int>& entrance)\n{\n std::queue<Position> que;\n que.push({static_cast<uint8_t>(entr... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 0 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& m, vector<int>& e) {\n int h=m.size(),w=m[0].size(),f=0,b=0,s=0,p,r,c,n,x,y;\n int q[10000],d[]={1,-1,w,-w};\n q[b++]=e[0]*w+e[1];\n m[e[0]][e[1]]='+';\n while(f<b){\n for(n=b-f;n--;){\n ... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 0 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n int m = maze.size();\n int n = maze[0].size();\n\n int row = entrance[0];\n int col = entrance[1];\n\n maze[row][col] = '-';\n\n queue<int> pos;\n int newI ... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 0 | {
"code": "class Solution {\npublic:\n bool isValid(int i, int j, int n, int m)\n {\n if(i == 0 or j == 0 or i == n-1 or j == m-1) return true;\n return false;\n }\n\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n int n = maze.size(), m = maze[0].size();\n\n ... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 0 | {
"code": "class Solution {\npublic:\n vector<vector<int>> dir={{0,1},{0,-1},{1,0},{-1,0}};\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n int n=maze.size();\n int m=maze[0].size();\n\n queue<pair<int,int>> q;\n q.push({entrance[0],entrance[1]});\n ma... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 0 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) { \n int m = maze[0].size(),n = maze.size();\n queue<pair<int,int>>q;\n \n q.push({entrance[0],entrance[1]});\n maze[entrance[0]][entrance[1]] = '+';\n int level = 0;\... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 0 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n queue<pair<int, int>> q;\n int answer = -1;\n set<pair<int, int>> invalid;\n set<pair<int, int>> directions = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};\n for (auto n : directio... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 0 | {
"code": "class Solution {\npublic:\n int dir[5] = {0, -1, 0, 1, 0};\n int nearestExit(vector<vector<char>>& m, vector<int>& ent) {\n queue<array<int, 3>> q; // i, j, steps\n q.push({ent[0], ent[1], 0});\n while(!q.empty()) {\n auto [i, j, steps] = q.front(); q.pop();\n ... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 1 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n int rows=maze.size(), cols=maze[0].size();\n vector<vector< int>> dirs= {{-1,0}, {1, 0}, {0, -1}, {0, 1}};\n int startrow=entrance[0], startcol=entrance[1];\n \n queue<ar... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 1 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n int m = maze.size(); // number of rows\n int n = maze[0].size(); // number of columns\n \n // BFS queue: stores row, column, and steps taken so far\n queue<pair<int, int>... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 1 | {
"code": "class Solution {\n public:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n constexpr int dirs[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};\n const int m = maze.size();\n const int n = maze[0].size();\n int ans = 0;\n queue<pair<int, int>> q{{{entrance[0], entrance[1]... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 1 | {
"code": "class Solution {\n\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n \n int rows = maze.size();\n int cols = maze[0].size();\n \n int stepsToExit = 0;\n \n vector<vector<bool>> visited(rows, vector<bool>(cols, false));\n ... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 1 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n const vector<pair<int, int>> directions{\n {0, 1}, {0, -1}, {-1, 0}, {1, 0}\n };\n vector<vector<bool>> visited(maze.size(), vector<bool>(maze[0].size(), false));\n q... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 1 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n int x[4]={1, 0, -1, 0};\n int y[4]={0, -1, 0, 1};\n int m=maze.size(), n=maze[0].size();\n int c=0;\n\n vector<vector<bool>>vis(m, vector<bool>(n, false));\n queue... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 1 | {
"code": "class Solution {\npublic:\n int fx(vector<vector<char>>&v,vector<vector<int>>&vis,int i,int j,vector<int>&v1){\n int n = v.size();\n int m = v[0].size();\n if((i!=v1[0] || j!=v1[1]) && (i==0 || i==n-1 || j==0 || j==m-1)){\n return 0;\n }\n int ans = 1e5;\n ... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 1 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n int m = maze.size();\n int n = maze[0].size();\n cout<<m<<n<<endl;\n int row = entrance[0];\n int col = entrance[1];\n // pair<int,pair<int,int>>\n vector<v... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 1 | {
"code": "#include <vector>\n#include <unordered_set>\n#include <queue>\n#include <string>\nusing namespace std;\n\nclass Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n unordered_set<string> exits;\n int m = maze.size();\n int n = maze[0].size();\... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 1 | {
"code": "class Solution {\npublic:\n #define fi first\n #define se second\n vector<pair<int , int>> dir = {{0 , 1} , {0 , -1} , {1 , 0} , {-1 , 0}};\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n int m = maze.size();\n int n = maze[0].size();\n vector<pair<int... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 1 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n queue<pair<int, int>> pos;\n bool visited[maze.size()][maze[0].size()];\n for (int i = 0; i < maze.size(); i++) {\n for (int j = 0; j < maze[0].size(); j++) {\n ... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 2 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n queue<pair<int, pair<int, int>>> q;\n q.push({0, {entrance[0], entrance[1]}});\n\n vector<vector<int>> vis(maze.size(), vector<int>(maze[0].size(), 0));\n\n vector<vector<int>> ... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 2 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n int m = maze.size(), n = maze[0].size();\n vector<vector<bool>> visited(m, vector<bool>(n, false));\n vector<vector<int>> distance(m, vector<int>(n, 0));\n queue<pair<int, int>> q;\n q.push(... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 2 | {
"code": "class Solution {\npublic:\n int dx[4] = {0,0,-1,1};\n int dy[4] = {-1,1,0,0};\n int nearestExit(vector<vector<char>>& a, vector<int>& ent) {\n int n = a.size();\n int m = a[0].size();\n int x = ent[0];\n int y = ent[1];\n char temp = a[x][y];\n a[x][y] = '... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 2 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n int m = maze.size(), n = maze[0].size();\n vector<vector<bool>> visited(m, vector<bool>(n, false));\n vector<vector<int>> distance(m, vector<int>(n, 1));\n queue<pair<pair<int, int>, int>> q;\n... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 2 | {
"code": "class Solution {\npublic:\n bool isInBound(int r, int c, int x, int y) {\n return x >= 0 && x < r && y >= 0 && y < c;\n }\n\n bool isExit(int r, int c, int i, int j) {\n return i == 0 || i == r - 1 || j == 0 || j == c - 1;\n }\n\n int nearestExit(vector<vector<char>>& maze, vec... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 2 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n vector<pair<int, int>> moves = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};\n vector<vector<int>> vis(maze.size(), vector<int>(maze[0].size(), -1));\n queue<pair<pair<int, int>, int>> tracker;\... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 2 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& arr, vector<int>& entrance) {\n int m=arr.size();\n int n=arr[0].size();\n vector<vector<int> > dp(m,vector<int>(n,-1));\n dp[entrance[0]][entrance[1]]=0; //src;\n vector<int> dx={1,-1,0,0};\n ve... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 2 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) \n {\n int n = maze.size();\n int m = maze[0].size();\n\n vector<int> row = {0,0,-1,1};\n vector<int> col = {-1,1,0,0};\n\n vector<pair<int,int>> exitPositions;\n\n ... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 2 | {
"code": "\nclass Solution {\n class NodeInfo {\n public:\n int sr;\n int sc;\n int step;\n NodeInfo (int r, int c, int s) : sr(r), sc(c), step(s) {}\n };\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n int row = maze.size(), col = maze... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 2 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n int m = maze.size();\n int n = maze[0].size();\n\n\n queue<pair<int, int>> q;\n\n vector<vector<int>> distance(m, vector<int>(n, INT_MAX));\n vector<vector<bool>> visited... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 2 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& e) {\n queue<pair<int,int>> q;\n q.push({e[0],e[1]});\n int dis=0;\n maze[e[0]][e[1]]='+';\n while(!q.empty()){\n int size=q.size();\n for(int i=0;i<size;i++){\n ... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 2 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n if (maze.empty()) return -1;\n int m = maze.size(), n = maze[0].size();\n\n queue<pair<int,int>> q;\n q.push({entrance[0], entrance[1]});\n maze[entrance[0]][entrance[1]]... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 2 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n int m = maze.size();\n int n = maze[0].size(); \n // vector<vector<bool>>visited(m,vector<bool>(n,false));\n int ex=entrance[0],ey=entrance[1];\n // if(ex==0 || ex==m-1 |... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 2 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n int entranceRow = entrance[0];\n int entranceCol = entrance[1];\n int m = maze.size();\n int n = maze[0].size();\n vector<vector<int>> helperArr(m, vector<int>(n, 0));\n ... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 2 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n queue<pair<int,pair<int,int>>>q;\n int n=maze.size();\n int m=maze[0].size();\n vector<vector<int>>vis(n,vector<int>(m,0));\n q.push({0,{entrance[0],entrance[1]}});\n ... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 2 | {
"code": "#pragma GCC optimize(\"O3,unroll-loops\")\nclass init {\n public:\n init() {\n ios_base::sync_with_stdio(0);\n cin.tie(nullptr);\n cout.tie(nullptr);\n }\n} Booster;\n\nclass Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n ... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 2 | {
"code": "class Solution {\npublic:\n bool isExit(const vector<vector<char>>& maze, const vector<int>& entrance, const pair<int,int>& cell) {\n if(cell.first == entrance[0] && cell.second == entrance[1]) return false;\n\n // is entrance\n if(cell.first-1 < 0 \n || cell.first+1 >= m... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 2 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n int m = maze.size();\n int n = maze[0].size(); \n vector<vector<bool>>visited(m,vector<bool>(n,false));\n int ex=entrance[0],ey=entrance[1];\n // if(ex==0 || ex==m-1 ||ey... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 2 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n queue<vector<int>> q;\n int m = maze.size(), n = maze[0].size();\n vector<vector<bool>> vis(maze.size(), vector<bool>(maze[0].size(),0));\n q.push({entrance[0],entrance[1],0});\... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 2 | {
"code": "int DI[] = {0, 1, 0, -1};\nint DJ[] = {1, 0, -1, 0};\nclass Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n pair<int,int> ent = make_pair(entrance[0], entrance[1]);\n queue<pair<int,int>> Q;\n Q.push(ent);\n set<pair<int,int>> S;\n... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 2 | {
"code": "class Solution {\npublic:\n int minCount = INT_MAX;\n bool isSafe(int xnew, int ynew, int n, int m) {\n if(xnew >= 0 && xnew < n && ynew >=0 && ynew < m) {\n return true;\n }\n return false;\n }\n void bfs(vector<vector<char>> &maze, vector<int> &entrance, vector... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 2 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n int m = maze.size();\n int n = maze[0].size();\n queue<tuple<int, int, int>> q;\n vector<vector<int>> visited(m, vector<int>(n, 0));\n\n visited[entrance[0]][entrance[1]]... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 2 | {
"code": "class Solution {\npublic:\n int isValid(int x, int y, int n, int m){\n return !(x<0 || x>=n || y<0 || y>=m);\n }\n\n int border(int x, int y, int n, int m){\n return (x==0 || x==n-1 || y==0 || y==m-1);\n }\n\n int nearestExit(vector<vector<char>>& maze, vector<int>& ent) {\n ... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 2 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n vector<vector<int>> dir = {{1, 0}, {0,1}, {0,-1}, {-1,0}};\n int m = maze.size();\n int n = maze[0].size();\n queue<vector<int>> q; // 0->i // 1->j // 2->distance\n q.pus... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "class Solution {\npublic:\n\n bool isSafe(vector<vector<char>>& maze, int m, int n, int i, int j) {\n return i>=0 && j>=0 && i<m && j<n && maze[i][j] == '.';\n }\n\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n\n // find all exists ( empty cells in the borde... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "class Solution {\n bool isBorder(int rows, int cols, int idx) {\n auto [row, col] = idxToPair(cols, idx);\n if (row == 0) {\n return true;\n }\n if (col == 0) {\n return true;\n }\n if (row == rows - 1) {\n return true;\n ... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "#include <vector>\n#include <queue>\n#include <utility>\n\nusing namespace std;\n\nclass Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& e) {\n int n = maze.size();\n int m = maze[0].size();\n vector<vector<int>> vis(n, vector<int>(m, 0));\n \n ... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n array<pair<int, int>, 4> dirs{{\n {-1, 0},\n {1, 0},\n {0, -1},\n {0, 1}\n }};\n\n const int n = maze.size();\n const int m = maze[0]... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n int min_path = INT_MAX;\n deque<vector<int>> go_to_lab;\n go_to_lab.push_back({entrance[0], entrance[1], 0});\n maze[entrance[0]][entrance[1]] = '+';\n int size = maze.si... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n int min_path = INT_MAX;\n deque<vector<int>> go_to_lab;\n go_to_lab.push_back({entrance[0], entrance[1], 0});\n maze[entrance[0]][entrance[1]] = '+';\n int size = maze.si... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "class Solution {\npublic:\n\n bool BorderCell( pair< int, int > cell , vector<vector< char>> &maze) {\n\n int r = cell.first;\n\n int c = cell.second;\n\n return r == 0 || r == maze.size() - 1 || c == 0 || c == maze[0].size() - 1;\n };\n\n vector< vector< int >> directions =... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n int m = maze.size(), n = maze[0].size();\n queue<vector<int>> q;\n q.push({entrance[0], entrance[1], 0});\n maze[entrance[0]][entrance[1]] = 0;\n vector<vector<int>> dirs... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "class Solution {\npublic:\n std::vector<std::pair<int,int>> m_dir={{-1,0},{1,0},{0,-1},{0,1}};\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n size_t nx=maze[0].size();\n size_t ny=maze.size();\n std::vector<std::vector<bool>>seen(maze.size(),std::vector<... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "class Solution {\npublic:\n std::vector<std::pair<int,int>> m_dir={{-1,0},{1,0},{0,-1},{0,1}};\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n size_t nx=maze[0].size();\n size_t ny=maze.size();\n std::vector<std::vector<bool>>seen(maze.size(),std::vector<... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "class Solution {\npublic:\n int bfs(vector<vector<char>>& maze, vector<vector<bool>> visited, int x, int y, int count, int ex, int ey, int m, int n) {\n //\n //cout << x << \" \" << y << endl;\n //cout << ex << \" \" << ey << endl;\n \n if ((x == 0 || x == m-1 || y == 0 || y ... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "class Solution {\npublic:\ntypedef long long ll;\n\n int bfs(vector<vector<char>>& maze,vector<int>& e){\n int n = maze.size(),m=maze[0].size();\n queue<pair<int,int>> q;\n q.push({e[0],e[1]});\n vector<vector<int>> visited(n,vector<int>(m,0));\n vector<vector<ll>> dis... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "class Solution {\npublic:\n int bfs(vector<vector<char>>& maze, int x, int y, int n, int m, vector<vector<int>>vis)\n {\n queue<vector<int>>q;\n q.push({x,y,0});\n vis[x][y]=1;\n while(!q.empty())\n {\n int x1=q.front()[0];\n int x2=q.front()[1... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "#include <iostream>\n\nclass Solution {\n\n void bfs(int32_t x, int32_t y, unordered_set<int64_t>& visited, vector<vector<char>>& maze, int steps, int& min_steps, queue<tuple<uint32_t, uint32_t, uint32_t>>& q)\n\n {\n int64_t xy = 0;\n xy |= x;\n xy <<=32;\n xy |= y;\n\n ... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n int m = maze.size();\n int n = maze[0].size();\n int dirs[][2] = {{0,1}, {0,-1}, {1,0}, {-1,0}};\n int steps = 1;\n vector<vector<int>> cells = {entrance};\n maze[... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n int m { static_cast<int>(maze.size()) };\n int n { static_cast<int>(maze[0].size()) };\n\n std::queue<std::pair<int, int>> positionBFSQueue {};\n positionBFSQueue.push(std::make... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n queue<vector<int>> q;\n int rows = maze.size();\n int cols = maze[0].size();\n // vector<vector<bool>> visited(rows, vector<bool>(cols, 0));\n set<pair<int, int>> st;\n ... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n queue<vector<int>> q;\n int rows = maze.size();\n int cols = maze[0].size();\n // vector<vector<bool>> visited(rows, vector<bool>(cols, 0));\n set<pair<int, int>> st;\n ... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "class Solution {\n\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n queue<vector<int>> toVisit;\n int i = entrance[0];\n int j = entrance[1];\n if(i==maze.size() - 1 || j==maze[0].size()-1 || i==0 || j==0)maze[i][j] = '+';\n int min = IN... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n // instantiate min-heap: pair of dist, coords\n priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<>> pq; \n\n int n = maze.size(), m = maze[0].size()... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "class Solution {\n\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n queue<vector<int>> toVisit;\n int i = entrance[0];\n int j = entrance[1];\n if(i==maze.size() - 1 || j==maze[0].size()-1 || i==0 || j==0)maze[i][j] = '+';\n int min = IN... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "class Solution {\n\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n queue<vector<int>> toVisit;\n int i = entrance[0];\n int j = entrance[1];\n if(i==maze.size() - 1 || j==maze[0].size()-1 || i==0 || j==0)maze[i][j] = '+';\n int min = IN... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "class Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n // mark entrance as 'x'\n maze[entrance[0]][entrance[1]] = 'x';\n\n int m = maze.size();\n int n = maze[0].size();\n\n queue<vector<int>> current_step_queue;\n mar... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "class Solution\n{\nprivate:\n using Position = struct\n {\n int x, y;\n };\n using VisitingMap = std::vector<std::vector<bool>>;\n using Map = std::vector<std::vector<char>>;\n using QueueItem = std::pair<Position, int>;\n using Queue = std::queue<QueueItem>;\n\n inline int m... |
2,038 | <p>You are given an <code>m x n</code> matrix <code>maze</code> (<strong>0-indexed</strong>) with empty cells (represented as <code>'.'</code>) and walls (represented as <code>'+'</code>). You are also given the <code>entrance</code> of the maze, where <code>entrance = [entrance<sub>row</sub>, entrance<... | 3 | {
"code": "class Solution {\npublic:\n bool isExit(vector<int> cell, vector<vector<char>>& maze) {\n if ((cell[0] > 0) && (cell[0] < maze.size()-1) && (cell[1] > 0) && (cell[1] < maze[0].size()-1)) {\n return false;\n }\n return true; \n }\n\n int nearestExit(vector<vector<cha... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.