question_slug
stringlengths
3
77
title
stringlengths
1
183
slug
stringlengths
12
45
summary
stringlengths
1
160
author
stringlengths
2
30
certification
stringclasses
2 values
created_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
updated_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
hit_count
int64
0
10.6M
has_video
bool
2 classes
content
stringlengths
4
576k
upvotes
int64
0
11.5k
downvotes
int64
0
358
tags
stringlengths
2
193
comments
int64
0
2.56k
nearest-exit-from-entrance-in-maze
C++ || BFS || Easy to Understand
c-bfs-easy-to-understand-by-mohakharjani-vnck
\nclass Solution {\npublic:\n vector<int>rowDir = {-1, 1, 0, 0};\n vector<int>colDir = {0, 0, -1, 1};\n bool isAtBorder(vector<vector<char>>&maze, int
mohakharjani
NORMAL
2022-11-21T00:45:00.606143+00:00
2022-11-21T00:45:00.606177+00:00
3,108
false
```\nclass Solution {\npublic:\n vector<int>rowDir = {-1, 1, 0, 0};\n vector<int>colDir = {0, 0, -1, 1};\n bool isAtBorder(vector<vector<char>>&maze, int row, int col)\n {\n if ((row == 0) || (row == maze.size() - 1)) return true;\n if ((col == 0) || (col == maze[0].size() - 1)) return true;\n...
16
2
['Breadth-First Search', 'Queue', 'C', 'C++']
3
nearest-exit-from-entrance-in-maze
DFS Anomaly
dfs-anomaly-by-kesharipiyush24-u414
I wasted hours debugging my DFS Solution and a lesson learned for life that I will never ever use DFS to find shortest path from now onwards.\n \nCode which is
KeshariPiyush24
NORMAL
2021-07-12T07:05:53.723200+00:00
2021-07-12T07:08:42.591301+00:00
2,100
false
I wasted hours debugging my DFS Solution and a lesson learned for life that I will never ever use DFS to find shortest path from now onwards.\n \nCode which is finally working:\n```java\nclass Solution {\n int[][] dp = new int[101][101];\n boolean[][] visited = new boolean[101][101];\n int i;\n int j;\n ...
16
1
['Dynamic Programming', 'Depth-First Search', 'Breadth-First Search', 'Graph', 'Recursion', 'Java']
4
nearest-exit-from-entrance-in-maze
Python 3 | BFS, Deque, In-place | Explanation
python-3-bfs-deque-in-place-explanation-amt5d
Explanation\n- Use BFS to find shortest/closest\n- Starting from entrance, if you see a . on the boarder and it\'s not the entrance, then that\'s a exit\n- Mark
idontknoooo
NORMAL
2021-07-10T18:45:20.848463+00:00
2021-07-10T18:45:20.848509+00:00
1,521
false
### Explanation\n- Use `BFS` to find shortest/closest\n- Starting from `entrance`, if you see a `.` on the boarder and it\'s not the entrance, then that\'s a exit\n- Mark visited place as `+` to avoid revisit (also we don\'t need to use a `visisted = set()` here)\n- We pass a 3rd parameter as the `step` we need to reac...
16
0
['Breadth-First Search', 'Queue', 'Python', 'Python3']
2
nearest-exit-from-entrance-in-maze
Simple BFS Solution | C++ without explanation
simple-bfs-solution-c-without-explanatio-s2x8
\nclass Solution {\npublic:\n int nearestExit(vector<vector<char>>& m, vector<int>& e) \n {\n int r=size(m);\n int c=size(m[0]); \n i
shivaye
NORMAL
2021-07-10T16:04:47.513731+00:00
2021-07-10T16:04:47.513758+00:00
1,010
false
```\nclass Solution {\npublic:\n int nearestExit(vector<vector<char>>& m, vector<int>& e) \n {\n int r=size(m);\n int c=size(m[0]); \n int i=e[0];\n int j=e[1];\n queue<pair<int,int>> q;\n int cnt=1;\n if(i+1<r and m[i+1][j]==\'.\')\n {\n q.push({...
12
0
[]
2
nearest-exit-from-entrance-in-maze
[JavaScript] Neat: bfs
javascript-neat-bfs-by-mxn42-4j2m
js\nconst nearestExit = (maze, [y0, x0]) => {\n maze[y0][x0] = \'@\'\n const queue = [[y0, x0, 0]]\n while (queue.length) {\n const [y, x, step]
mxn42
NORMAL
2022-11-21T02:06:26.177749+00:00
2024-02-24T20:17:45.264999+00:00
1,087
false
```js\nconst nearestExit = (maze, [y0, x0]) => {\n maze[y0][x0] = \'@\'\n const queue = [[y0, x0, 0]]\n while (queue.length) {\n const [y, x, step] = queue.shift()\n for (const [dy, dx] of [[-1, 0], [0, -1], [1, 0], [0, 1]]) {\n const ny = y + dy, nx = x + dx\n if (!maze[ny]...
11
0
['JavaScript']
2
nearest-exit-from-entrance-in-maze
Simple BFS using Java | O(m*n) time and O(1) space.
simple-bfs-using-java-omn-time-and-o1-sp-z9bi
\n# Approach\n Describe your approach to solving the problem. \nSimple BFS using a Queue Data Structure.\n\n# Complexity\n- Time complexity: O(m * n)\n Add your
eshwaraprasad
NORMAL
2024-08-27T17:50:37.272770+00:00
2024-08-27T17:50:37.272811+00:00
1,002
false
\n# Approach\n<!-- Describe your approach to solving the problem. -->\nSimple **BFS** using a Queue Data Structure.\n\n# Complexity\n- Time complexity: O(m * n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java [...
10
0
['Breadth-First Search', 'Java']
1
nearest-exit-from-entrance-in-maze
✔️ C++ solution | BFS
c-solution-bfs-by-coding_menance-j2ks
The better approach to this question is using breadth-first-search (BFS) than depth-first-search (DFS)\n\nC++ []\nclass Solution {\npublic:\n int nearestExit(v
coding_menance
NORMAL
2022-11-21T03:19:15.790386+00:00
2022-11-21T03:19:15.790421+00:00
2,519
false
The better approach to this question is using breadth-first-search (BFS) than depth-first-search (DFS)\n\n``` C++ []\nclass Solution {\npublic:\n int nearestExit(vector<vector<char>>& grid, vector<int>& e) {\n int y= grid.size() ,yend= grid.size() - 1, x= grid[0].size() ,xend= grid[0].size() - 1, answer = 0;\n \...
10
0
['Breadth-First Search', 'C++']
0
nearest-exit-from-entrance-in-maze
Issues with DFS code identified!!! | C++ | Working + Not Working Solution
issues-with-dfs-code-identified-c-workin-t4on
The solution below passes all the test cases.\n\n\nclass Solution {\npublic: \n typedef long long ll;\n ll dp[105][105];\n bool seen[105][105];\n
dedoced
NORMAL
2021-07-10T19:24:00.352318+00:00
2021-07-10T19:26:14.645116+00:00
1,004
false
The solution below passes all the test cases.\n\n```\nclass Solution {\npublic: \n typedef long long ll;\n ll dp[105][105];\n bool seen[105][105];\n int x[4] = {1, -1, 0, 0};\n int y[4] = {0, 0, 1, -1};\n int srcx, srcy;\n ll rec(vector<vector<char>>& arr, int row, int col){\n \n if...
9
0
[]
6
nearest-exit-from-entrance-in-maze
WHY TLE WITH DFS?? PLS HELP
why-tle-with-dfs-pls-help-by-shivambunge-ltbj
Im counting all the possible path lengths and returning min of them\n```\nclass Solution:\n def nearestExit(self, maze: List[List[str]], entrance: List[int])
ShivamBunge
NORMAL
2021-07-10T16:06:11.992455+00:00
2021-07-10T16:07:40.917313+00:00
889
false
Im counting all the possible path lengths and returning min of them\n```\nclass Solution:\n def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n n=len(maze)\n m=len(maze[0])\n ans=[]\n def dfs(maze,i,j,c,visited):\n \n if [i,j]!=entrance and (i...
9
3
[]
3
nearest-exit-from-entrance-in-maze
C++ SOLUTION USING BFS
c-solution-using-bfs-by-shruti_mahajan-dovp
\nclass Solution {\npublic:\n vector<int> r={0,0,-1,1};\n vector<int> c={-1,1,0,0};\n int nearestExit(vector<vector<char>>& ma, vector<int>& e) {\n
shruti_mahajan
NORMAL
2021-07-10T16:01:29.051058+00:00
2021-07-10T19:28:17.536788+00:00
950
false
```\nclass Solution {\npublic:\n vector<int> r={0,0,-1,1};\n vector<int> c={-1,1,0,0};\n int nearestExit(vector<vector<char>>& ma, vector<int>& e) {\n int n=ma.size(),m=ma[0].size(),res=0;\n int s1=e[0],s2=e[1];\n queue<pair<int,int>> q;\n ma[s1][s2]=\'+\';\n q.push({s1,s2});...
9
3
[]
4
nearest-exit-from-entrance-in-maze
✅✅✅ 614 ms, faster than 98.64% of Python3 || Easy to Understand
614-ms-faster-than-9864-of-python3-easy-xo7nu
\n\n# Intuition\nThe maze consists of open spaces (\'.\') and walls (\'+\'). An exit is defined as any open space located at the boundary of the maze, excluding
denyskulinych
NORMAL
2024-05-24T21:30:47.665590+00:00
2024-05-24T21:30:47.665615+00:00
1,253
false
![\u0421\u043D\u0438\u043C\u043E\u043A \u044D\u043A\u0440\u0430\u043D\u0430 2024-05-24 \u0432 17.09.15.png](https://assets.leetcode.com/users/images/610e0cd8-7c7a-4cf6-9b1c-5bae67df53db_1716585777.35953.png)\n\n# Intuition\nThe maze consists of open spaces (\'.\') and walls (\'+\'). An exit is defined as any open space...
8
0
['Breadth-First Search', 'Queue', 'Python3']
2
nearest-exit-from-entrance-in-maze
Python3 Breadth First Search Solution
python3-breadth-first-search-solution-by-x2pm
\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n# Code\n\nclass Solution:\n def nearestExit(self, maze: List[List[str]], entrance: Lis
palak29jain05
NORMAL
2023-12-16T19:12:17.584653+00:00
2023-12-16T19:12:17.584674+00:00
858
false
\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n# Code\n```\nclass Solution:\n def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n m = len(maze)\n n = len(maze[0])\n\n queue = collections.deque()\n queue.append((entrance[0], entrance[1], 0))\...
7
0
['Python3']
2
nearest-exit-from-entrance-in-maze
✅[C++] Just do BFS !!......still getting TLE? See, Why
c-just-do-bfs-still-getting-tle-see-why-gzqys
Thought Process:\nSince it is asked to get the shortest path (nearest exit), first thought that should come to us is BFS.\nTHATS IT !!\n\n\nclass Solution {\npu
devil16
NORMAL
2022-11-21T06:39:10.461868+00:00
2022-11-21T06:39:10.461915+00:00
1,145
false
# Thought Process:\nSince it is asked to get the shortest path (nearest exit), first thought that should come to us is **BFS**.\nTHATS IT !!\n\n```\nclass Solution {\npublic:\n bool check_constraint (int i, int j, int m, int n){\n return (i >= 0 && i < m && j >= 0 && j < n);\n }\n \n bool check_bound...
7
0
['C']
2
nearest-exit-from-entrance-in-maze
[Go] Solution BFS || 100% memory || 90+% runtime
go-solution-bfs-100-memory-90-runtime-by-gedb
Code\n\nfunc nearestExit(maze [][]byte, entrance []int) int {\n\tq := [][2]int{{entrance[0], entrance[1]}}\n\tm, n := len(maze), len(maze[0])\n\tmaze[entrance[0
user9647qb
NORMAL
2022-11-21T06:07:39.464416+00:00
2022-11-21T06:07:39.464448+00:00
558
false
# Code\n```\nfunc nearestExit(maze [][]byte, entrance []int) int {\n\tq := [][2]int{{entrance[0], entrance[1]}}\n\tm, n := len(maze), len(maze[0])\n\tmaze[entrance[0]][entrance[1]] = \'+\'\n\n\tsteps := 0\n\tfor len(q) > 0 {\n\t\tfor _, v := range q {\n\t\t\tq = q[1:]\n\t\t\tif (v[0] == m-1 || v[1] == n-1 || v[0] == 0 ...
7
0
['Go']
3
nearest-exit-from-entrance-in-maze
✅ Python, Easy to understand BFS, 97.74%
python-easy-to-understand-bfs-9774-by-an-0p5f
\nclass Solution:\n def nearestExit(self, maze: List[List[str]], entr: List[int]) -> int:\n rows, cols = len(maze), len(maze[0])\n deq = deque(
AntonBelski
NORMAL
2022-07-03T21:30:23.092680+00:00
2022-07-18T11:53:00.942488+00:00
822
false
```\nclass Solution:\n def nearestExit(self, maze: List[List[str]], entr: List[int]) -> int:\n rows, cols = len(maze), len(maze[0])\n deq = deque()\n deq.append([entr[0], entr[1], -1])\n \n while deq:\n r, c, dist = deq.popleft()\n if not (0 <= r < rows and 0 ...
7
0
['Breadth-First Search', 'Python']
3
nearest-exit-from-entrance-in-maze
a few solutions
a-few-solutions-by-claytonjwong-chng
Perform BFS from start.\n\n---\n\nKotlin\n\nclass Solution {\n fun nearestExit(A: Array<CharArray>, start: IntArray): Int {\n var depth = 0\n v
claytonjwong
NORMAL
2021-07-10T16:00:33.161359+00:00
2021-07-10T16:19:56.753716+00:00
718
false
Perform BFS from `start`.\n\n---\n\n*Kotlin*\n```\nclass Solution {\n fun nearestExit(A: Array<CharArray>, start: IntArray): Int {\n var depth = 0\n var (M, N) = listOf(A.size, A[0].size)\n var isExit = { i: Int, j: Int -> i == 0 || i == M - 1 || j == 0 || j == N - 1 }\n var q: Queue<Pair...
7
0
[]
2
nearest-exit-from-entrance-in-maze
✅[Java] Solution using BFS✅
java-solution-using-bfs-by-staywithsaksh-b8js
Simply apply BFS on Matrix code as gived below:\n\nclass Solution {\n public int nearestExit(char[][] maze, int[] entrance) {\n int r = maze.length, c
staywithsaksham
NORMAL
2022-11-21T07:40:59.103524+00:00
2022-11-21T07:40:59.103561+00:00
737
false
Simply apply BFS on Matrix code as gived below:\n```\nclass Solution {\n public int nearestExit(char[][] maze, int[] entrance) {\n int r = maze.length, c = maze[0].length;\n int[][] directions = new int[][]{{1, 0}, {-1, 0}, {0, 1}, {0, -1}};\n \n int sr = entrance[0], sc = entrance[1];\n ...
6
0
['Breadth-First Search', 'Graph', 'Queue', 'Java']
1
nearest-exit-from-entrance-in-maze
Detailed C++ Standard Approaches BFS Approach
detailed-c-standard-approaches-bfs-appro-y1ca
This question can easily solved using a standard BFS algorithm.\n\nWe must do BFS step by step starting from the entrance and iterating level by level, so one o
sahooc029
NORMAL
2022-11-21T05:06:39.625453+00:00
2022-11-21T06:01:20.072487+00:00
1,406
false
This question can easily solved using a standard **BFS** algorithm.\n\nWe must do **BFS** step by step starting from the entrance and iterating level by level, so one of the paths that we choose will be the minimum path (if it exists).\n\n**Idea :** using **BFS** to find shortest path. \n\n\n**Complexity**\nSpace Compl...
6
0
['Breadth-First Search', 'Graph', 'C']
2
nearest-exit-from-entrance-in-maze
Rust using queue and set
rust-using-queue-and-set-by-yosuke-furuk-ot1w
Code\n\nuse std::collections::VecDeque;\nuse std::collections::HashSet;\n\nimpl Solution {\n pub fn nearest_exit(maze: Vec<Vec<char>>, entrance: Vec<i32>) ->
yosuke-furukawa
NORMAL
2022-11-21T01:40:36.445289+00:00
2022-11-21T01:40:36.445331+00:00
618
false
# Code\n```\nuse std::collections::VecDeque;\nuse std::collections::HashSet;\n\nimpl Solution {\n pub fn nearest_exit(maze: Vec<Vec<char>>, entrance: Vec<i32>) -> i32 {\n let mut queue = VecDeque::new();\n let mut visited = HashSet::new();\n queue.push_back((entrance[0] as usize, entrance[1] as ...
6
1
['Rust']
1
nearest-exit-from-entrance-in-maze
BFS Clean c# solution
bfs-clean-c-solution-by-rchshld-ivge
\n public int NearestExit(char[][] maze, int[] entrance) {\n var dirs = new [] {0, 1, 0, -1, 0};\n var q = new Queue<(int, int, int)>();\n
rchshld
NORMAL
2022-05-01T15:50:40.222293+00:00
2022-05-01T15:50:40.222337+00:00
283
false
```\n public int NearestExit(char[][] maze, int[] entrance) {\n var dirs = new [] {0, 1, 0, -1, 0};\n var q = new Queue<(int, int, int)>();\n q.Enqueue((entrance[0], entrance[1], 0));\n \n while(q.Any())\n {\n var (i, j, dist) = q.Dequeue();\n if(i < 0 ...
6
0
['Breadth-First Search', 'C#']
0
nearest-exit-from-entrance-in-maze
Python BFS
python-bfs-by-kyathamomkar-mox8
\nclass Solution:\n def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n ex,ey = entrance\n rows = len(maze)\n co
kyathamomkar
NORMAL
2021-07-16T07:18:18.560173+00:00
2021-07-16T07:18:18.560226+00:00
260
false
```\nclass Solution:\n def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n ex,ey = entrance\n rows = len(maze)\n cols = len(maze[0])\n \n def onBorder(r,c): #check if cell is on the border and not the entrance cell\n if (r in [0,rows-1] or c in ...
6
0
[]
0
nearest-exit-from-entrance-in-maze
C++ | Straightforward BFS | Faster than 91%
c-straightforward-bfs-faster-than-91-by-9o02o
\nclass Solution {\npublic:\n int m,n;\n int dx[4] = {0,0,1,-1};\n int dy[4] = {1,-1,0,0};\n bool isBorder(int i,int j){\n return (i==0 || i=
aparna_g
NORMAL
2021-07-14T19:49:16.615450+00:00
2021-07-14T19:49:34.543791+00:00
1,317
false
```\nclass Solution {\npublic:\n int m,n;\n int dx[4] = {0,0,1,-1};\n int dy[4] = {1,-1,0,0};\n bool isBorder(int i,int j){\n return (i==0 || i==m-1 || j == 0 || j == n-1);\n }\n \n bool valid(int r,int c){\n return (r>=0 && c>=0 && r<m && c<n);\n }\n \n int nearestExit(vecto...
6
0
['Breadth-First Search', 'C', 'C++']
1
nearest-exit-from-entrance-in-maze
java accepted BFS solution
java-accepted-bfs-solution-by-anmol676-eqq6
This Problem is similiar to walls and land question on leetcode. Just apply the BFS . we are given a starting point . So apply BFS from that only on empty cell
anmol676
NORMAL
2021-07-10T16:15:43.381614+00:00
2021-07-10T16:20:27.261162+00:00
630
false
This Problem is similiar to **walls and land** question on leetcode. Just apply the BFS . we are given a starting point . So apply BFS from that only on empty cells and whenever we are at 1st row, or 1st column or last row or last column simply return that level. \n\'\'\'\nclass Solution {\n public int nearestExit...
6
1
['Breadth-First Search', 'Java']
3
nearest-exit-from-entrance-in-maze
Solution By Dare2Solve | Detailed Explanation | Clean Code
solution-by-dare2solve-detailed-explanat-1yg1
Explanation []\nauthorslog.com/blog/xkpfvNACri\n\n# Code\n\ncpp []\nclass Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entr
Dare2Solve
NORMAL
2024-08-22T08:57:46.472594+00:00
2024-08-22T08:57:46.472628+00:00
1,188
false
```Explanation []\nauthorslog.com/blog/xkpfvNACri\n```\n# Code\n\n```cpp []\nclass Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n vector<tuple<int, int, int>> st;\n int rows = maze.size();\n int cols = maze[0].size();\n\n for (int i = 0; i < r...
5
0
['Matrix', 'Python', 'C++', 'Java', 'Python3', 'JavaScript']
0
nearest-exit-from-entrance-in-maze
Fully Step by step explanation. BFS Solution
fully-step-by-step-explanation-bfs-solut-bwn6
Intuition\nThe problem involves finding the nearest exit from a given entrance in a maze. We can use Breadth-First Search (BFS) to explore possible paths from t
OtabekJurabekov
NORMAL
2024-01-11T06:16:18.040348+00:00
2024-01-11T06:16:18.040378+00:00
209
false
# Intuition\nThe problem involves finding the nearest exit from a given entrance in a maze. We can use Breadth-First Search (BFS) to explore possible paths from the entrance and stop when we reach an exit.\n\n# Approach\n1. **Initialize**: Start by initializing the maze, the entrance coordinates, and the directions to ...
5
0
['C++']
0
nearest-exit-from-entrance-in-maze
BFS Solution | C++
bfs-solution-c-by-manannjain-nr1d
Intuition\nStarting in every direction from the entrance we move by 1 step and as soon we approach a boundary return the steps.\n\n# Approach\nApply BFS which w
manannjain
NORMAL
2022-11-21T19:45:05.913298+00:00
2022-11-21T19:45:05.913328+00:00
596
false
# Intuition\nStarting in every direction from the entrance we move by 1 step and as soon we approach a boundary return the steps.\n\n# Approach\nApply BFS which works radially outwards from the entrance point.\n\n# Complexity\n- Time complexity:\nO(N^2)\n\n- Space complexity:\nO(N)\n\n# Code\n```\nclass Solution {\npub...
5
0
['C++']
0
nearest-exit-from-entrance-in-maze
JAVA || Why BFS || Simple Steps
java-why-bfs-simple-steps-by-jain2013103-h1x0
Steps to follow:\n1. Whenever you come accross a question asking for the shortest distance, Go for BFS as in DFS the first route may not be the shortest one but
jain20131035
NORMAL
2022-11-21T04:47:16.563719+00:00
2022-11-21T04:47:16.563762+00:00
987
false
Steps to follow:\n1. Whenever you come accross a question asking for the shortest distance, **Go for BFS** as in DFS the first route may not be the shortest one but BFS assures the shortest path.\n2. We need to take a **Queue and a Visited Array**.\n3. Queue is to add all the nodes breath wise at each iteration\n4. Vis...
5
0
['Breadth-First Search', 'Java']
0
nearest-exit-from-entrance-in-maze
Fastest, Python BFS solution
fastest-python-bfs-solution-by-beneath_o-zo5o
\nclass Solution:\n def nearestExit(self, grid: List[List[str]], entrance: List[int]) -> int:\n m=len(grid)\n n=len(grid[0])\n lst=[[ent
beneath_ocean
NORMAL
2022-10-17T11:25:22.849703+00:00
2022-10-17T11:25:22.849735+00:00
1,413
false
```\nclass Solution:\n def nearestExit(self, grid: List[List[str]], entrance: List[int]) -> int:\n m=len(grid)\n n=len(grid[0])\n lst=[[entrance[0],entrance[1],0]]\n visited=[[-1]*n for i in range(m)]\n row=[-1,1,0,0]\n col=[0,0,-1,1]\n visited[entrance[0]][entrance[1...
5
0
['Breadth-First Search', 'Graph', 'Python', 'Python3']
1
nearest-exit-from-entrance-in-maze
Simple BFS (C++) code
simple-bfs-c-code-by-rajat241302-bp0w
\nclass Solution\n{\n\tqueue<pair<int, int>> q1;\n\tvector<vector<int>> visited;\n\tint bfs(vector<vector<char>> &grid, int i, int j, vector<vector<int>> visi)\
rajat241302
NORMAL
2022-06-04T17:10:43.580497+00:00
2022-06-04T17:10:43.580544+00:00
829
false
```\nclass Solution\n{\n\tqueue<pair<int, int>> q1;\n\tvector<vector<int>> visited;\n\tint bfs(vector<vector<char>> &grid, int i, int j, vector<vector<int>> visi)\n\t{\n\t\tint xn[] = {1, -1, 0, 0};\n\t\tint yn[] = {0, 0, -1, 1};\n\t\tqueue<pair<int, int>> q;\n\t\tvisited[i][j] = 1;\n\t\tq.push({i, j});\n\t\tq1.push({i...
5
0
['Depth-First Search', 'Breadth-First Search', 'Graph', 'Queue', 'C', 'C++']
0
nearest-exit-from-entrance-in-maze
C++ Solution using BFS (with comments)
c-solution-using-bfs-with-comments-by-ar-vkhh
The main idea is to perform BFS in all 4 directions and return the number of steps as soon as you find a valid empty cell.\n\n\nclass Solution {\npublic:\n /
archit-dev
NORMAL
2022-05-26T16:18:11.365198+00:00
2022-05-26T16:18:11.365243+00:00
281
false
The main idea is to perform BFS in all 4 directions and return the number of steps as soon as you find a valid empty cell.\n\n```\nclass Solution {\npublic:\n //checks if the coordinates of the cell are that of an unvisited valid empty cell\n bool isValid(int x,int y,int n,int m, vector<vector<char>>& maze,vector...
5
0
['Breadth-First Search', 'Graph', 'C']
0
nearest-exit-from-entrance-in-maze
[Python 3] BFS - Clean, simple easy to understand
python-3-bfs-clean-simple-easy-to-unders-s9fc
\ndef nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n\tm, n = len(maze), len(maze[0])\n\tq = deque([(entrance[0], entrance[1])])\n\tstep
dolong2110
NORMAL
2022-04-27T11:24:25.603994+00:00
2022-04-27T11:24:25.604022+00:00
364
false
```\ndef nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n\tm, n = len(maze), len(maze[0])\n\tq = deque([(entrance[0], entrance[1])])\n\tsteps = 0\n\twhile q:\n\t\tl = len(q)\n\t\tfor _ in range(l):\n\t\t\tr, c = q.popleft()\n\t\t\tif r < 0 or r == m or c < 0 or c == n or maze[r][c] == \'+\':\n\t\...
5
0
['Breadth-First Search', 'Python', 'Python3']
0
nearest-exit-from-entrance-in-maze
Python and C++ Solution with Explanation - BFS
python-and-c-solution-with-explanation-b-jxvs
It is a commonly known concept that we can use either DFS or BFS to find if there is a path from one node to another in a graph. You check out Abdul Bari\u2019s
vishnusreddy
NORMAL
2021-07-11T11:26:08.661622+00:00
2021-07-11T11:26:08.661654+00:00
2,093
false
It is a commonly known concept that we can use either DFS or BFS to find if there is a path from one node to another in a graph. You check out Abdul Bari\u2019s video on YouTube if you want a clear about both of these traversals.\n\nThe basic idea here is to perform a breadth-first search on the given input matrix look...
5
0
['Breadth-First Search', 'C', 'Python', 'C++']
4
nearest-exit-from-entrance-in-maze
C++ | BFS | Easy and intuitive
c-bfs-easy-and-intuitive-by-technisrahul-3pig
\nclass Solution {\npublic:\n bool isSafe(int i,int j ,int r,int c){\n if(i<0 || i >=r || j <0 || j >=c) return false;\n return true;\n }\n
technisRahulk
NORMAL
2021-07-10T19:12:59.211158+00:00
2021-07-10T19:12:59.211191+00:00
249
false
``` \nclass Solution {\npublic:\n bool isSafe(int i,int j ,int r,int c){\n if(i<0 || i >=r || j <0 || j >=c) return false;\n return true;\n }\n bool isExit(int i,int j,int r ,int c){\n if(i!=0 and j!=0 and i!=r-1 and j!=c-1) return false;\n return true; \n }\n int nearestExi...
5
1
[]
1
nearest-exit-from-entrance-in-maze
C++ Easy DFS+Memoization
c-easy-dfsmemoization-by-vaibhtan1997-jqtm
```\nclass Solution {\npublic:\n vector> dp;\n \n bool isExit(int i,int j,int m,int n,vector& entrance)\n {\n //Exit lies at the edges of the
vaibhtan1997
NORMAL
2021-07-10T16:33:08.988287+00:00
2021-07-11T08:00:21.710994+00:00
384
false
```\nclass Solution {\npublic:\n vector<vector<long int>> dp;\n \n bool isExit(int i,int j,int m,int n,vector<int>& entrance)\n {\n //Exit lies at the edges of the maze and entrance can\'t be the exit\n if(i!=entrance[0]||j!=entrance[1])\n {\n if(i==0||j==0||i==m-1||j==n-1)\n...
5
3
[]
4
nearest-exit-from-entrance-in-maze
Python BFS solution
python-bfs-solution-by-savikx-eveb
\nclass Solution:\n def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n m, n = len(maze), len(maze[0])\n node = tuple(e
savikx
NORMAL
2021-07-10T16:11:41.203956+00:00
2021-07-10T16:27:49.850296+00:00
430
false
```\nclass Solution:\n def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n m, n = len(maze), len(maze[0])\n node = tuple(entrance)\n q = deque([node])\n level = 0\n visited = set([node])\n while q:\n for _ in range(len(q)):\n ...
5
0
['Breadth-First Search', 'Python']
0
nearest-exit-from-entrance-in-maze
easy simple solution
easy-simple-solution-by-harithe_curious_-9w3q
please up vote :)Code
hariTHE_CURIOUS_CODER
NORMAL
2025-01-02T08:37:52.746098+00:00
2025-01-02T08:37:52.746098+00:00
524
false
please up vote :) # Code ```cpp [] class Solution { public: int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) { int dir[4][2] = {{0,-1},{-1,0},{0,1},{1,0}}; int m = maze.size(); int n = maze[0].size(); int moves = 1 ; queue<pair<int,int>> q ; ...
4
0
['C++']
0
nearest-exit-from-entrance-in-maze
Detailed Solution for beginners 🤗🤗🤗🤗
detailed-solution-for-beginners-by-utkar-5gp3
Welcome, I hope you will have a wonderfull day \uD83E\uDD17\uD83E\uDD17\uD83E\uDD17\uD83E\uDD17\n\nNow, on to the Solution \u23ED\uFE0F\n# Approach\n\n1. Define
utkarshpriyadarshi5026
NORMAL
2024-05-08T12:00:06.266168+00:00
2024-05-08T12:00:06.266194+00:00
377
false
# Welcome, I hope you will have a wonderfull day \uD83E\uDD17\uD83E\uDD17\uD83E\uDD17\uD83E\uDD17\n\nNow, on to the Solution \u23ED\uFE0F\n# Approach\n\n1. **Define a Helper Class for Coordinates**\nWe begin by defining a helper class Cord to store the coordinates (`x` and `y`), as well as the distance from the entranc...
4
0
['Breadth-First Search', 'Graph', 'Java']
1
nearest-exit-from-entrance-in-maze
Easy to Understand JS Solution | Detailed Explanation | BFS
easy-to-understand-js-solution-detailed-vw871
Intuition\nMaybe it\'s all the practice solving graph related problems but when I read this one, I immediately thought BFS from the starting point to the border
pokaru
NORMAL
2023-11-29T15:48:51.657002+00:00
2023-11-29T15:48:51.657025+00:00
386
false
# Intuition\nMaybe it\'s all the practice solving graph related problems but when I read this one, I immediately thought BFS from the starting point to the border of the grid.\n\n# Approach\nStarting at `entrance`. I performed BFS until a reached the border of the maze. `getNeighbors` is a helper method for returning ...
4
0
['Breadth-First Search', 'JavaScript']
1
nearest-exit-from-entrance-in-maze
JS Graph BFS w/ Intuitive Comments
js-graph-bfs-w-intuitive-comments-by-gno-15nu
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
gnoman
NORMAL
2023-08-23T22:45:11.086908+00:00
2023-08-23T22:45:11.086930+00:00
370
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
4
0
['JavaScript']
0
nearest-exit-from-entrance-in-maze
simple & easy BFS solution
simple-easy-bfs-solution-by-yash_visavad-nmvt
Code\nPython [0]\nclass Solution:\n def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n n, m = len(maze), len(maze[0])\n
yash_visavadia
NORMAL
2023-07-29T14:46:58.336606+00:00
2023-07-29T14:46:58.336630+00:00
712
false
# Code\n``` Python [0]\nclass Solution:\n def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n n, m = len(maze), len(maze[0])\n \n q = []\n q.append([entrance[0], entrance[1]])\n \n ans = 0\n while q:\n temp = q.copy()\n q....
4
0
['Array', 'Breadth-First Search', 'Matrix', 'Python3']
1
nearest-exit-from-entrance-in-maze
Easy to Understand Code in C++ with explanation
easy-to-understand-code-in-c-with-explan-w13w
Approach\nIt is a simple BFS solution in which we are storing pair of indexes and its length from start in a queue and also a visited array to take care we not
kingp
NORMAL
2022-12-26T06:36:56.465385+00:00
2022-12-26T06:37:15.919599+00:00
111
false
# Approach\nIt is a simple BFS solution in which we are storing pair of indexes and its length from start in a queue and also a visited array to take care we not again go to the same path and if we reach at the edge then we have to return the length.. \nBelow is my C++ code with 95% runtime\n\n\n# Code\n```\nclass Solu...
4
0
['Breadth-First Search', 'Graph', 'Queue', 'C++']
0
nearest-exit-from-entrance-in-maze
Simple Python BFS Solution
simple-python-bfs-solution-by-segnides-izg6
Intuition\nStart from the entrance, do BFS and expand the search, if we are out of the maze, return the distance travelled\n\n# Approach\n- start from the entra
segnides
NORMAL
2022-12-11T10:43:26.188723+00:00
2022-12-11T10:43:26.188775+00:00
456
false
# Intuition\nStart from the entrance, do BFS and expand the search, if we are out of the maze, return the distance travelled\n\n# Approach\n- start from the entrance of maze\n- expand the search using BFS updating the distance travelled for every cell\n- if we are out of the maze, then return the current distance\n\n# ...
4
0
['Breadth-First Search', 'Python3']
0
nearest-exit-from-entrance-in-maze
JAVA | 2 solutions | BFS
java-2-solutions-bfs-by-sourin_bruh-2to6
Please Upvote :D\n##### 1. Using an extra 2D \'visited\' array:\n\nclass Solution {\n public int nearestExit(char[][] maze, int[] entrance) {\n int m
sourin_bruh
NORMAL
2022-11-21T11:41:37.099647+00:00
2022-11-21T11:42:49.598704+00:00
247
false
### **Please Upvote** :D\n##### 1. Using an extra 2D \'visited\' array:\n```\nclass Solution {\n public int nearestExit(char[][] maze, int[] entrance) {\n int m = maze.length, n = maze[0].length;\n int[][] direction = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};\n\n Queue<int[]> q = new LinkedList<>();\n...
4
0
['Breadth-First Search', 'Queue', 'Java']
0
nearest-exit-from-entrance-in-maze
Rust BFS
rust-bfs-by-xiaoping3418-zajq
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
xiaoping3418
NORMAL
2022-11-21T00:28:37.253521+00:00
2022-11-21T00:28:37.253567+00:00
742
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(N)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$...
4
0
['Rust']
0
nearest-exit-from-entrance-in-maze
C++ || EASY || BFS
c-easy-bfs-by-segfault_00-5p7w
\nclass Solution {\npublic:\n int dx[4] = {1 , -1, 0 ,0};\n int dy[4] = { 0 ,0 , -1 ,1};\n int nearestExit(vector<vector<char>>& maze, vector<int>& ent
segfault_00
NORMAL
2022-06-19T17:42:30.787507+00:00
2022-06-19T17:52:07.057287+00:00
259
false
```\nclass Solution {\npublic:\n int dx[4] = {1 , -1, 0 ,0};\n int dy[4] = { 0 ,0 , -1 ,1};\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n \n int n = maze.size() , m = maze[0].size();\n queue<pair<int , int >> q;\n vector<vector<bool>> visited(n , vector<bo...
4
0
['Breadth-First Search', 'Graph', 'Queue', 'C', 'Matrix']
0
nearest-exit-from-entrance-in-maze
Beats 100% BFS Solution in Python with Explanation!
beats-100-bfs-solution-in-python-with-ex-eup3
Approach: Breadth-First Search (BFS)Problem Breakdown Given amazerepresented as a 2D grid, where: .represents open paths. +represents walls. We start at a giv
jxmils
NORMAL
2025-02-19T21:08:40.499057+00:00
2025-02-19T21:08:40.499057+00:00
642
false
### `Approach: Breadth-First Search (BFS)` #### `Problem Breakdown` - Given a `maze` represented as a 2D grid, where: - `.` represents open paths. - `+` represents walls. - We start at a given `entrance` and must find the shortest path to the nearest exit. - An exit is any open cell `.` on the boundary of the grid...
3
0
['Python3']
1
nearest-exit-from-entrance-in-maze
Python | BFS | Easy to Understand | Beats 86%
python-bfs-easy-to-understand-beats-86-b-kr7e
Hope my code helps!\n\nBFS -- Beats 86%\n\nclass Solution:\n def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n """\n
Coder1918
NORMAL
2024-04-01T23:14:09.115400+00:00
2024-04-01T23:14:09.115429+00:00
860
false
Hope my code helps!\n\nBFS -- Beats 86%\n```\nclass Solution:\n def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n """\n > With BFS, The first exit it comes across is the closest exit\n > Level represents number of steps ahead\n """\n m, n = len(maze), len(...
3
0
['Breadth-First Search', 'Graph', 'Python3']
1
nearest-exit-from-entrance-in-maze
Simple C++ solution.. striver type approach ..simple bfs ..
simple-c-solution-striver-type-approach-x4wro
Intuition\n Describe your first thoughts on how to solve this problem. \neverything is explained in code comments\n\n# Approach\n Describe your approach to solv
kalpit04
NORMAL
2024-03-28T06:44:02.691667+00:00
2024-03-28T06:44:02.691698+00:00
314
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\neverything is explained in code comments\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add yo...
3
0
['C++']
0
nearest-exit-from-entrance-in-maze
fastest solution, beats 100% with an old school trick
fastest-solution-beats-100-with-an-old-s-34w3
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n- I modify maze to mark visited cells\n- I use "loop unrolling" technique
sva7777
NORMAL
2023-07-30T14:43:20.896741+00:00
2023-07-30T14:50:14.008499+00:00
712
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n- I modify maze to mark visited cells\n- I use "loop unrolling" technique to look up, down, left, right\n\n\n# Complexity\n- Time complexity:\nBeats 100%\n\n\n- Space complexity:\nBeats 66.3%\n\n# Code\n```\nclass Solution:\...
3
0
['Python3']
1
nearest-exit-from-entrance-in-maze
C++, BFS, clean code
c-bfs-clean-code-by-arif-kalluru-5fic
Code\n\n// BFS\nclass Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n int m = maze.size(), n = maze[0].si
Arif-Kalluru
NORMAL
2023-07-27T18:52:32.604491+00:00
2023-07-27T18:52:32.604522+00:00
191
false
# Code\n```\n// BFS\nclass Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n int m = maze.size(), n = maze[0].size(); \n int DIR[][2] = { {0,-1}, {1,0}, {0,1}, {-1,0} };\n // r, c, steps\n queue<array<int, 3>> Q;\n Q.push({ entrance[0], ...
3
0
['Array', 'Breadth-First Search', 'Matrix', 'C++']
0
nearest-exit-from-entrance-in-maze
DFS Solution, Only successful DFS code till now. Explained.
dfs-solution-only-successful-dfs-code-ti-py5x
A question which tells you dfs will not necessarily give you the shortest path. \n*\nMy thinking: Firstly I applied only dfs, it gave me a TLE. Next I tried to
jaiswalshash
NORMAL
2022-11-22T05:12:42.795653+00:00
2022-11-22T05:12:42.795688+00:00
780
false
### A question which tells you dfs will not necessarily give you the shortest path. \n****\nMy thinking: Firstly I applied only dfs, it gave me a TLE. Next I tried to optimize it using memoization as there could be a possiblity of revisiting a cell multiple times. Final test case was not giving me the correct output, a...
3
0
['Depth-First Search', 'Java']
1
nearest-exit-from-entrance-in-maze
😃 Python BFS Easy with comments
python-bfs-easy-with-comments-by-drbless-frgf
We perform a breadth-first search of the maze, using a queue.\n\n\nclass Solution:\n def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int
drblessing
NORMAL
2022-11-21T20:22:57.149996+00:00
2022-11-21T20:22:57.150021+00:00
582
false
We perform a breadth-first search of the maze, using a queue.\n\n```\nclass Solution:\n def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n # BFS \n rows, cols = len(maze), len(maze[0])\n \n # Set visited spaces to "+"\n maze[entrance[0]][entrance[1]] = \'+\...
3
0
['Breadth-First Search', 'Queue', 'Python', 'Python3']
1
nearest-exit-from-entrance-in-maze
C++ || BFS || GOOD EXPLAINED CODE || EASY
c-bfs-good-explained-code-easy-by-batman-rzaj
\n*************************************** DON\'T FORGET TO UPVOTE*****************************************\n\n\nclass Solution {\npublic:\n // APPROACH : BAS
batman14
NORMAL
2022-11-21T09:27:29.949314+00:00
2022-11-21T09:27:29.949352+00:00
171
false
```\n*************************************** DON\'T FORGET TO UPVOTE*****************************************\n\n\nclass Solution {\npublic:\n // APPROACH : BASIC APPLIED BFS ALGORITHM\n // T(O)=O(linear) && S(O)=O(linear)\n \n int nearestExit(vector<vector<char>>& maze, vector<int>& entran...
3
0
['Breadth-First Search', 'Graph', 'Queue', 'C', 'C++']
0
nearest-exit-from-entrance-in-maze
Java Solution Using BFS
java-solution-using-bfs-by-abhai0306-be5h
\n\nclass Pair\n{\n int row;\n int col;\n int steps;\n Pair(int _row , int _col , int _steps)\n {\n this.row = _row;\n this.col = _
abhai0306
NORMAL
2022-11-21T09:11:49.844156+00:00
2022-11-21T09:11:49.844193+00:00
952
false
\n```\nclass Pair\n{\n int row;\n int col;\n int steps;\n Pair(int _row , int _col , int _steps)\n {\n this.row = _row;\n this.col = _col;\n this.steps = _steps;\n }\n}\n\nclass Solution \n{\n public int nearestExit(char[][] maze, int[] entrance) \n {\n Queue<Pair> q ...
3
0
['Breadth-First Search', 'Java']
0
nearest-exit-from-entrance-in-maze
Python BFS Solution O(n*m)
python-bfs-solution-onm-by-energyboy-ko6q
\nclass Solution:\n def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n \n ROWS, COLS = len(maze), len(maze[0])\n
energyboy
NORMAL
2022-11-21T08:26:33.694053+00:00
2022-11-21T08:26:33.694085+00:00
464
false
```\nclass Solution:\n def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n \n ROWS, COLS = len(maze), len(maze[0])\n visited = set()\n queue = deque()\n queue.append((tuple(entrance), 0))\n \n while queue:\n element = queue.popleft()...
3
0
['Breadth-First Search', 'Queue', 'Python']
1
nearest-exit-from-entrance-in-maze
USING QUEUE (BFS)
using-queue-bfs-by-saurav9283-isxa
\nclass Solution {\npublic:\n vector<int> rowDir = {-1,1,0,0};\n vector<int> colDir = {0,0,1,-1};\n bool border(vector<vector<char>> &maze , int row ,
saurav9283
NORMAL
2022-11-21T07:45:42.416626+00:00
2022-11-21T07:45:42.416672+00:00
33
false
```\nclass Solution {\npublic:\n vector<int> rowDir = {-1,1,0,0};\n vector<int> colDir = {0,0,1,-1};\n bool border(vector<vector<char>> &maze , int row , int col)\n {\n if((row == 0) || (row == maze.size()-1))\n {\n return true;\n }\n if((col == 0) || (col == maze[0].s...
3
0
['C']
0
nearest-exit-from-entrance-in-maze
✅ EZ Python || BFS
ez-python-bfs-by-0xsapra-5bvf
\nclass Solution:\n def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n """\n . entrace cant be termed as exit cell
0xsapra
NORMAL
2022-11-21T07:18:26.303844+00:00
2022-11-21T07:18:26.303879+00:00
769
false
```\nclass Solution:\n def nearestExit(self, maze: List[List[str]], entrance: List[int]) -> int:\n """\n . entrace cant be termed as exit cell\n """\n \n seen = set()\n exits = set()\n R, C = len(maze), len(maze[0])\n entrance = tuple(entrance)\n \n ...
3
0
['Python']
0
nearest-exit-from-entrance-in-maze
Beginner Friendly Standard BFS [8ms]
beginner-friendly-standard-bfs-8ms-by-cr-383d
class Solution {\n\n public int nearestExit(char[][] maze, int[] entrance) {\n int rows = maze.length, cols = maze[0].length;\n \n Queue
crusifixx
NORMAL
2022-11-21T05:09:19.911703+00:00
2022-11-21T05:09:19.911744+00:00
10
false
class Solution {\n\n public int nearestExit(char[][] maze, int[] entrance) {\n int rows = maze.length, cols = maze[0].length;\n \n Queue<int[]> queue = new LinkedList<>();\n boolean[][] visited = new boolean[rows][cols];\n \n int[][] dirs = {{0,1},{0,-1},{1,0},{-1,0}}; //dir...
3
0
['Breadth-First Search']
0
nearest-exit-from-entrance-in-maze
✅ JS || Multiple Approaches || Easy to understand
js-multiple-approaches-easy-to-understan-964a
I just found this Blog and Github repository with solutions to Leetcode problems.\nhttps://leet-codes.blogspot.com/2022/11/nearest-exit-from-entrance-in-maze.ht
pmistry_
NORMAL
2022-11-21T03:59:47.954485+00:00
2022-11-21T03:59:47.954528+00:00
1,634
false
I just found this Blog and Github repository with solutions to Leetcode problems.\nhttps://leet-codes.blogspot.com/2022/11/nearest-exit-from-entrance-in-maze.html\nIt has solutions to almost every problem on Leetcode, and I recommend checking it out.\nNote: You can bookmark it as a resource, and approach. Other approac...
3
0
['JavaScript']
1
nearest-exit-from-entrance-in-maze
CPP | Faster than O(n^2) | Easy to Read
cpp-faster-than-on2-easy-to-read-by-bhal-xm6b
1926. Nearest Exit from Entrance in Maze\n#\n# CPP Code\n\nclass Solution {\npublic:\n \n vector<int> dx = {-1, 0, 1, 0};\n vector<int> dy = {0, 1, 0,
bhalerao-2002
NORMAL
2022-11-21T02:39:51.443107+00:00
2022-11-21T02:39:51.443153+00:00
66
false
# 1926. Nearest Exit from Entrance in Maze\n#\n# CPP Code\n```\nclass Solution {\npublic:\n \n vector<int> dx = {-1, 0, 1, 0};\n vector<int> dy = {0, 1, 0, -1};\n \n int nearestExit(vector<vector<char>>& a, vector<int>& st) {\n queue<vector<int>> q;\n st.push_back(0);\n q.push(st);\n...
3
0
['C++']
0
nearest-exit-from-entrance-in-maze
C# Queue
c-queue-by-anand9589-g7n5
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
anand9589
NORMAL
2022-11-21T01:22:05.930360+00:00
2022-11-21T01:22:05.930383+00:00
526
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
3
0
['C#']
1
nearest-exit-from-entrance-in-maze
Golang | BFS
golang-bfs-by-yfw13-ke4s
\ntype State struct {\n r, c, l int\n}\n\nfunc nearestExit(maze [][]byte, entrance []int) int {\n m, n := len(maze), len(maze[0])\n q := []State{{entra
tw13
NORMAL
2022-11-21T00:38:30.215836+00:00
2022-11-21T00:38:30.215899+00:00
414
false
```\ntype State struct {\n r, c, l int\n}\n\nfunc nearestExit(maze [][]byte, entrance []int) int {\n m, n := len(maze), len(maze[0])\n q := []State{{entrance[0], entrance[1], 0}}\n v := make(map[State]struct{})\n var state, vState State\n var rr, cc int\n d4 := [][]int{{1, 0}, {-1, 0}, {0, 1}, {0, ...
3
0
['Go']
0
nearest-exit-from-entrance-in-maze
C | 105ms(100%) & 7.4MB(100%) | BFS & Link list
c-105ms100-74mb100-bfs-link-list-by-peih-f32j
Intuition\n Describe your first thoughts on how to solve this problem. \nUsing BFS by link list\n# Approach\n Describe your approach to solving the problem. \n1
peihao61
NORMAL
2022-11-21T00:33:18.947888+00:00
2022-11-21T08:05:20.968560+00:00
509
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUsing BFS by link list\n# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Start from entrance and add link list\n2. Find next empty cells, \'.\', until the exit\n# Complexity\n- Time complexity: O(n)\n<!-- Add your t...
3
0
['C']
0
nearest-exit-from-entrance-in-maze
Simple java solution
simple-java-solution-by-siddhant_1602-1o9x
```\nclass Solution {\n public int nearestExit(char[][] m, int[] e) {\n int c=0;\n Queue nm=new LinkedList<>();\n int a[][]={{0,1},{1,0}
Siddhant_1602
NORMAL
2022-08-03T08:06:24.314349+00:00
2022-08-03T08:06:24.314390+00:00
219
false
```\nclass Solution {\n public int nearestExit(char[][] m, int[] e) {\n int c=0;\n Queue<int[]> nm=new LinkedList<>();\n int a[][]={{0,1},{1,0},{-1,0},{0,-1}};\n nm.offer(e);\n boolean k[][]=new boolean[m.length][m[0].length];\n k[e[0]][e[1]]=true;\n while(!nm.isEmpty...
3
0
['Breadth-First Search', 'Java']
0
nearest-exit-from-entrance-in-maze
Easy BFS Solution With Comments and approach
easy-bfs-solution-with-comments-and-appr-vppc
INTUITION: From the entrance start a bfs for all the four directions and stop if you reach any border cells and they are not walls.\n\nclass Solution {\npublic
karan252
NORMAL
2022-07-07T23:59:07.662613+00:00
2022-07-07T23:59:07.662640+00:00
207
false
INTUITION: From the entrance start a bfs for all the four directions and stop if you reach any border cells and they are not walls.\n```\nclass Solution {\npublic:\n int dx[4]={0,0,-1,1}; \n int dy[4]={1,-1,0,0};\n int nearestExit(vector<vector<char>>& maze, vector<int>& entrance) {\n int n=maze.size()...
3
0
['Breadth-First Search', 'Queue', 'C', 'C++']
1
nearest-exit-from-entrance-in-maze
ola ola
ola-ola-by-fr1nkenstein-ri4q
\nclass Solution {\n public int nearestExit(char[][] maze, int[] e) {\n int dx[]={1,-1,0,0};\n int dy[]={0,0,-1,1};\n if(maze[0].length=
fr1nkenstein
NORMAL
2022-06-02T18:05:36.633710+00:00
2022-06-02T18:05:36.633761+00:00
54
false
```\nclass Solution {\n public int nearestExit(char[][] maze, int[] e) {\n int dx[]={1,-1,0,0};\n int dy[]={0,0,-1,1};\n if(maze[0].length==1&&maze.length==1||maze[e[0]][e[1]]==\'+\')return -1;\n Queue<int[]>p=new LinkedList<>();\n int a[]={e[0],e[1],0};\n p.add(a);\n ...
3
0
[]
0
nearest-exit-from-entrance-in-maze
C++ || BFS || IN-DEPTH Analysis
c-bfs-in-depth-analysis-by-beast_123-mvjl
c++\nFirst I Thought We Have To Find The Nearest Exit Cell Coordinate Manhattan Distance From The Given Position.\nI Solved This Question Keeping The Above Thou
Beast_123
NORMAL
2021-10-15T09:14:12.781023+00:00
2021-10-15T13:55:35.280773+00:00
262
false
**c++**\nFirst I Thought We Have To Find The Nearest Exit Cell Coordinate Manhattan Distance From The Given Position.\nI Solved This Question Keeping The Above Thought In Mind.\n\nAnd Here\'s The Code \n**Suprisingly It has passed 188 test Cases Out of 194**\n```\nvector<int> dir={-1,0,1,0,-1};\n int nearestExit(vec...
3
0
['Breadth-First Search', 'C', 'Matrix']
0
nearest-exit-from-entrance-in-maze
Java Code, faster than 100.00% of Java online submissions. using BFS
java-code-faster-than-10000-of-java-onli-0089
\n public int nearestExit(char[][] maze, int[] entrance) {\n LinkedList<Integer> que = new LinkedList<>();\n int n = maze.length, m = maze[0].
vishalgupta171099
NORMAL
2021-07-12T05:25:26.747012+00:00
2021-07-12T05:25:50.191539+00:00
160
false
```\n public int nearestExit(char[][] maze, int[] entrance) {\n LinkedList<Integer> que = new LinkedList<>();\n int n = maze.length, m = maze[0].length;\n que.addLast(entrance[0] * m + entrance[1]);\n maze[entrance[0]][entrance[1]] = \'+\';\n int [][]dir = {{0, 1}, {1,...
3
0
[]
0
nearest-exit-from-entrance-in-maze
JavaScript and TypeScript Clean Code
javascript-and-typescript-clean-code-by-jabiv
JavaScript:\njs\nconst dir = [[0, 1], [0, -1], [1, 0], [-1, 0]];\nconst WALKED = \'-\', WALL = \'+\', NO_EXIT = -1;\n\n/**\n * @param {character[][]} maze\n * @
menheracapoo
NORMAL
2021-07-11T10:32:49.906884+00:00
2021-07-11T13:07:14.385784+00:00
682
false
JavaScript:\n```js\nconst dir = [[0, 1], [0, -1], [1, 0], [-1, 0]];\nconst WALKED = \'-\', WALL = \'+\', NO_EXIT = -1;\n\n/**\n * @param {character[][]} maze\n * @param {number[]} entrance\n * @return {number}\n */\nvar nearestExit = function(maze, entrance) {\n const m = maze.length, n = maze[0].length;\n const [ey,...
3
2
['TypeScript', 'JavaScript']
2
nearest-exit-from-entrance-in-maze
BFS Solution without Vis. Matrix (commented)
bfs-solution-without-vis-matrix-commente-kcik
\nclass Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entry) {\n int n = maze.size(), m = maze[0].size();\n ve
suraj013
NORMAL
2021-07-10T16:33:46.421452+00:00
2021-07-23T09:42:13.848632+00:00
134
false
```\nclass Solution {\npublic:\n int nearestExit(vector<vector<char>>& maze, vector<int>& entry) {\n int n = maze.size(), m = maze[0].size();\n vector<vector<int>> dist(n, vector <int> (m, 0));\n queue <pair <int, int>> q;\n int i = entry[0], j = entry[1];\n\t\tq.push({i, j}); // insert ...
3
0
['Breadth-First Search', 'C++']
0
nearest-exit-from-entrance-in-maze
SOLVED-JAVA BFS
solved-java-bfs-by-yaoyuanzhang06-db0w
\nclass Solution {\n public int nearestExit(char[][] maze, int[] entrance) {\n int[][] directions = new int[][]{{0,1},{0,-1},{1,0},{-1,0}};\n i
yaoyuanzhang06
NORMAL
2021-07-10T16:05:34.532881+00:00
2022-03-04T20:10:54.761186+00:00
735
false
```\nclass Solution {\n public int nearestExit(char[][] maze, int[] entrance) {\n int[][] directions = new int[][]{{0,1},{0,-1},{1,0},{-1,0}};\n int m = maze.length;\n int n = maze[0].length;\n \n int count =0;\n int result =Integer.MAX_VALUE;\n Queue<int[]> queue = new...
3
0
['Breadth-First Search', 'Java']
9
nearest-exit-from-entrance-in-maze
Simple C++ || BFS || Straight-Forward Solution ||
simple-c-bfs-straight-forward-solution-b-72fo
\nclass Solution {\npublic:\n int dir[5]={0,1,0,-1,0};\n int nearestExit(vector<vector<char>>& maze, vector<int>& e) {\n vector<vector<bool>>vi
satvikshrivas
NORMAL
2021-07-10T16:05:06.583263+00:00
2021-07-11T17:50:14.839366+00:00
454
false
```\nclass Solution {\npublic:\n int dir[5]={0,1,0,-1,0};\n int nearestExit(vector<vector<char>>& maze, vector<int>& e) {\n vector<vector<bool>>vis(maze.size(),vector<bool>(maze[0].size(),0));\n queue<vector<int>>q;\n q.push({e[0],e[1],0});\n vis[e[0]][e[1]]=1;\n while(!q.em...
3
0
['Breadth-First Search', 'C']
2
nearest-exit-from-entrance-in-maze
Java BFS
java-bfs-by-vikrant_pc-qkgl
\npublic int nearestExit(char[][] maze, int[] entrance) {\n\tint[][] directions = new int[][] {{0,1}, {1,0}, {0,-1},{-1,0}};\n\tQueue<Integer> queue = new Linke
vikrant_pc
NORMAL
2021-07-10T16:00:42.014912+00:00
2021-07-10T16:08:14.433823+00:00
331
false
```\npublic int nearestExit(char[][] maze, int[] entrance) {\n\tint[][] directions = new int[][] {{0,1}, {1,0}, {0,-1},{-1,0}};\n\tQueue<Integer> queue = new LinkedList<>();\n\tqueue.offer(entrance[0]); queue.offer(entrance[1]);\n\tfor(int currentDistance = 0; !queue.isEmpty(); currentDistance++) {\n\t\tint n = queue.s...
3
2
[]
0
nearest-exit-from-entrance-in-maze
✅✅ Classical BFS || Beginner Friendly || Easy Solution
classical-bfs-beginner-friendly-easy-sol-6208
IntuitionWe need to find the shortest path from the entrance to any exit in the maze. Since we are looking for the shortest path in an unweighted grid, BFS is t
Karan_Aggarwal
NORMAL
2025-03-19T17:50:38.970916+00:00
2025-03-19T17:50:38.970916+00:00
252
false
# Intuition We need to find the shortest path from the entrance to any exit in the maze. Since we are looking for the shortest path in an unweighted grid, **BFS** is the optimal approach. # Approach 1. **Initialize BFS**: - Push the `entrance` into a queue and mark it as visited (`'+'`). - Use a `directions`...
2
0
['Array', 'Breadth-First Search', 'Matrix', 'C++']
0
nearest-exit-from-entrance-in-maze
✅Beats 100% | ✅BFS Solution | C++
beats-100-bfs-solution-c-by-sajal0701-7wcg
🚀 Nearest Exit in a Maze🧠 IntuitionThe problem asks us to find the shortest path from a given entrance to any exit in the maze. Since we're looking for the shor
Sajal0701
NORMAL
2025-02-03T18:40:51.725161+00:00
2025-02-03T18:40:51.725161+00:00
323
false
# 🚀 Nearest Exit in a Maze ## 🧠 Intuition The problem asks us to find the shortest path from a given entrance to any exit in the maze. Since we're looking for the shortest path, we can apply **Breadth-First Search (BFS)**. - **BFS** ensures that we explore all possible paths level by level, and the first exit we e...
2
0
['C++']
0
nearest-exit-from-entrance-in-maze
Python 💯| Simple BFS | 😊
python-simple-bfs-by-ashishgupta291-yq65
Intuitionwe have to find shortest path from entrance to nearest cell at border with ".", we can use Dijkstra algo. since cost is same for all the movements simp
ashishgupta291
NORMAL
2025-01-30T13:11:34.328330+00:00
2025-01-30T13:11:34.328330+00:00
296
false
# Intuition we have to find shortest path from entrance to nearest cell at border with ".", we can use Dijkstra algo. since cost is same for all the movements simple bfs will also work. <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --...
2
0
['Python']
0
nearest-exit-from-entrance-in-maze
Java Optimal , Simple Approach
java-optimal-simple-approach-by-user8176-ken9
Nearest Exit from Entrance in MazeProblem DescriptionYou are given an m x n maze (a 2D grid) where: '.' represents an empty cell, '#' represents a wall, The ent
user8176ZR
NORMAL
2025-01-23T04:29:42.429031+00:00
2025-01-23T04:29:42.429031+00:00
260
false
# Nearest Exit from Entrance in Maze ## Problem Description You are given an `m x n` maze (a 2D grid) where: - `'.'` represents an empty cell, - `'#'` represents a wall, - The entrance is represented by a specific cell in the maze given as an array `entrance` of length 2, i.e., `[entrance[0], entrance[1]]`. The goal ...
2
0
['Breadth-First Search', 'Matrix', 'Java']
0
nearest-exit-from-entrance-in-maze
✅Easy to understand✅ Beats 100%
easy-to-understand-beats-100-by-mithun00-kmr9
IntuitionThe problem involves finding the shortest path from the given entrance to the nearest exit in a maze. Each exit lies on the boundary of the maze, and t
Mithun005
NORMAL
2025-01-10T05:34:34.667917+00:00
2025-01-10T05:34:34.667917+00:00
576
false
# Intuition The problem involves finding the shortest path from the given entrance to the nearest exit in a maze. Each exit lies on the boundary of the maze, and the path must traverse only empty cells (denoted by '.'). The shortest path can be efficiently computed using Breadth-First Search (BFS), which explores all p...
2
0
['Python3']
0
nearest-exit-from-entrance-in-maze
BFS | 49ms | 100% Beats | PHP
bfs-49ms-100-beats-php-by-ma7med-r8n5
Code
Ma7med
NORMAL
2025-01-09T15:16:31.956999+00:00
2025-01-15T08:41:39.151683+00:00
484
false
# Code ```php [] class Solution { /** * @param String[][] $maze * @param Integer[] $entrance * @return Integer */ function nearestExit($maze, $entrance) { $rows = count($maze); $cols = count($maze[0]); $directions = [[0, 1], [1, 0], [0, -1], [-1, 0]]; ...
2
0
['PHP']
0
nearest-exit-from-entrance-in-maze
C++ 0ms 35MB
c-0ms-35mb-by-lng205-lx9p
IntuitionBFS search with performance optimization.Approach Mark the cell as visited when adding it to the queue is the key. Otherwise all the previous cells in
lng205
NORMAL
2024-12-30T13:36:24.324586+00:00
2025-02-26T06:47:40.168124+00:00
206
false
![image.png](https://assets.leetcode.com/users/images/99f2d291-3c32-4bb7-a990-15923be76160_1735565773.647695.png) # Intuition <!-- Describe your first thoughts on how to solve this problem. --> BFS search with performance optimization. # Approach <!-- Describe your approach to solving the problem. --> - Mark the cel...
2
0
['C++']
0
nearest-exit-from-entrance-in-maze
✅ Simple solution + Why bfs not dfs
simple-solution-why-bfs-not-dfs-by-ibrah-flck
IntuitionMy first intuition was that I need a graph traversal algorithm; maybe DFS or BFS. I used DFS at first, but I hit time limit, when I tried BFS, the solu
IbrahimMohammed47
NORMAL
2024-12-26T15:49:13.912689+00:00
2024-12-26T15:56:10.345807+00:00
167
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> My first intuition was that I need a graph traversal algorithm; maybe DFS or BFS. I used DFS at first, but I hit time limit, when I tried BFS, the solution was accepted. # But Why BFS Not DFS? ## Why DFS is bad? DFS will rush deep down a s...
2
0
['Breadth-First Search', 'JavaScript']
0
nearest-exit-from-entrance-in-maze
✅ Easy Peasy Approach || C++ || Beats 100% 😮😮
easy-peasy-approach-c-beats-100-by-swaga-xaxv
Intuition\nThe problem requires finding the shortest path to an exit in a maze from a given starting position (entrance). This resembles a shortest path search,
Swagat003
NORMAL
2024-10-28T19:48:06.388708+00:00
2024-10-29T09:00:53.717620+00:00
539
false
# Intuition\nThe problem requires finding the shortest path to an exit in a maze from a given starting position (entrance). This resembles a **shortest path** search, which is efficiently handled by **Breadth-First Search (BFS)** since BFS explores nodes level by level, ensuring that the first exit found is the closest...
2
0
['Breadth-First Search', 'Graph', 'C++']
1
nearest-exit-from-entrance-in-maze
C# BFS Solution
c-bfs-solution-by-getrid-sj7u
Intuition\n Describe your first thoughts on how to solve this problem. To solve the problem of finding the shortest path to the nearest exit in the maze, we can
GetRid
NORMAL
2024-09-10T20:13:05.735942+00:00
2024-09-10T20:13:36.231610+00:00
101
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->To solve the problem of finding the shortest path to the nearest exit in the maze, we can approach it as a breadth-first search (BFS) problem. BFS is ideal for exploring all possible paths from the entrance, layer by layer, to ensure that t...
2
0
['Array', 'Breadth-First Search', 'Matrix', 'C#']
2
nearest-exit-from-entrance-in-maze
Python BFS solution- beats 96% in time and 91% in space
python-bfs-solution-beats-96-in-time-and-9wd3
Intuition\nThis problem can be solved using the Breadth-first search since the minimum number of steps has to be found from a start point. \n\n# Approach\n1. In
aditi2003pai
NORMAL
2024-07-31T16:28:09.661964+00:00
2024-07-31T16:28:09.661998+00:00
424
false
# Intuition\nThis problem can be solved using the Breadth-first search since the minimum number of steps has to be found from a start point. \n\n# Approach\n1. Initialize a queue with in which each entry is a list of 3 elements- [x, y, distance/steps so far].\n2. Append the entrance point with steps 0 to the queue.\n3....
2
0
['Python']
0
nearest-exit-from-entrance-in-maze
simple BFS || c++
simple-bfs-c-by-dipanshughime-137i
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
dipanshughime
NORMAL
2024-06-26T13:38:35.573399+00:00
2024-06-26T13:38:35.573423+00:00
236
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
2
0
['C++']
0
nearest-exit-from-entrance-in-maze
Beat 80% java solution ✅ || BFS
beat-80-java-solution-bfs-by-apophis29-g5bl
\n\nclass Pair{\n int first;\n int second;\n int step;\n Pair(int fst,int scnd,int step){\n this.first=fst;\n this.second=scnd;\n
Apophis29
NORMAL
2024-03-31T04:39:26.434478+00:00
2024-03-31T04:39:26.434510+00:00
285
false
```\n\nclass Pair{\n int first;\n int second;\n int step;\n Pair(int fst,int scnd,int step){\n this.first=fst;\n this.second=scnd;\n this.step=step;\n }\n}\n\nclass Solution {\n public int nearestExit(char[][] maze, int[] entrance) {\n int n=maze.length;\n int m=maze...
2
0
[]
0
nearest-exit-from-entrance-in-maze
Easy BFS solution (self explanatory with code comments) - Beats 100%
easy-bfs-solution-self-explanatory-with-k2qmz
Intuition\n Describe your first thoughts on how to solve this problem. \nStarting from the entrance position, perform BFS until we find a boundary cell. Return
vinaygarg25
NORMAL
2023-12-11T01:46:50.412145+00:00
2023-12-11T01:47:00.811389+00:00
442
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nStarting from the entrance position, perform BFS until we find a boundary cell. Return -1 if we don\'t \n# Complexity\n- Time complexity: O(m x n) - traversing each cell only once \n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\...
2
0
['Breadth-First Search', 'Java']
0
nearest-exit-from-entrance-in-maze
💡Swift - Optimal Solution - Breadth-First Search
swift-optimal-solution-breadth-first-sea-vtyx
Solution\n\nclass Solution {\n struct Index: Hashable {\n let x, y: Int\n }\n func nearestExit(_ maze: [[Character]], _ entrance: [Int]) -> Int
bernikovich
NORMAL
2023-11-24T09:23:30.863541+00:00
2023-11-24T09:23:30.863564+00:00
45
false
# Solution\n```\nclass Solution {\n struct Index: Hashable {\n let x, y: Int\n }\n func nearestExit(_ maze: [[Character]], _ entrance: [Int]) -> Int {\n let n = maze.count\n let m = maze[0].count\n\n let startIndex = Index(x: entrance[1], y: entrance[0])\n\n var visited: Set<...
2
0
['Breadth-First Search', 'Swift']
0
minimum-window-substring
Here is a 10-line template that can solve most 'substring' problems
here-is-a-10-line-template-that-can-solv-lct0
I will first give the solution then show you the magic template.\n\nThe code of solving this problem is below. It might be the shortest among all solutions prov
zjh08177
NORMAL
2015-12-02T21:18:34+00:00
2018-10-27T01:23:06.183054+00:00
906,127
false
I will first give the solution then show you the magic template.\n\n**The code of solving this problem is below. It might be the shortest among all solutions provided in Discuss**.\n\n string minWindow(string s, string t) {\n vector<int> map(128,0);\n for(auto c: t) map[c]++;\n int c...
6,827
111
['String']
271
minimum-window-substring
Solution
solution-by-deleted_user-0fsy
C++ []\nclass Solution {\npublic:\n string minWindow(string s, string t) {\n vector<int> map(128,0);\n for (char c : t) {\n map[c]++
deleted_user
NORMAL
2023-02-09T13:22:28.117867+00:00
2023-03-09T09:57:41.400293+00:00
57,001
false
```C++ []\nclass Solution {\npublic:\n string minWindow(string s, string t) {\n vector<int> map(128,0);\n for (char c : t) {\n map[c]++;\n }\n\n int counter = t.size(), begin = 0, end = 0, d = INT_MAX, head = 0;\n while (end < s.size()){\n if (map[s[end++]]-- ...
512
3
['C++', 'Java', 'Python3']
28
minimum-window-substring
12 lines Python
12-lines-python-by-stefanpochmann-5rwt
The current window is s[i:j] and the result window is s[I:J]. In need[c] I store how many times I need character c (can be negative) and missing tells how many
stefanpochmann
NORMAL
2015-08-05T09:20:09+00:00
2018-10-11T02:38:03.036357+00:00
105,664
false
The current window is `s[i:j]` and the result window is `s[I:J]`. In `need[c]` I store how many times I need character `c` (can be negative) and `missing` tells how many characters are still missing. In the loop, first add the new character to the window. Then, if nothing is missing, remove as much as possible from the...
481
43
['Python']
80
minimum-window-substring
🚀🚀🚀 BEATS 100% || EXPLAiNED ✅✅✅ || ANY LANGUAGE ✅✅✅ || 🚀🚀🚀 by PRODONiK
beats-100-explained-any-language-by-prod-7gfe
\n\n# Intuition\nThe goal is to find the minimum window in string s that contains all characters from string t. The intuition is to use a sliding window approac
prodonik
NORMAL
2024-02-04T00:10:06.073893+00:00
2024-02-04T00:27:15.408613+00:00
63,657
false
![image.png](https://assets.leetcode.com/users/images/ece090fc-bfe3-4c72-92fe-b15fdd757704_1707004998.8177435.png)\n\n# Intuition\nThe goal is to find the minimum window in string `s` that contains all characters from string `t`. The intuition is to use a sliding window approach with two pointers.\n\n# Approach\n- Init...
433
2
['C++', 'Java', 'Go', 'Python3', 'Ruby', 'C#']
18
minimum-window-substring
【Video】Sliding Window solution
video-sliding-window-solution-by-niits-gnec
Intuition\nUse a sliding window to find the smallest range that contains all characters in string t.\n\n---\n\n# Solution Video\n\nhttps://youtu.be/WGNaHa4853Q\
niits
NORMAL
2024-09-08T15:28:25.162602+00:00
2024-09-08T15:28:25.162635+00:00
34,664
false
# Intuition\nUse a sliding window to find the smallest range that contains all characters in string t.\n\n---\n\n# Solution Video\n\nhttps://youtu.be/WGNaHa4853Q\n\n### \u2B50\uFE0F\u2B50\uFE0F Don\'t forget to subscribe to my channel! \u2B50\uFE0F\u2B50\uFE0F\n\n**\u25A0 Subscribe URL**\nhttp://www.youtube.com/channel...
431
0
['C++', 'Java', 'Python3', 'JavaScript']
7
minimum-window-substring
Java solution. using two pointers + HashMap
java-solution-using-two-pointers-hashmap-6bvz
public class Solution {\n public String minWindow(String s, String t) {\n if(s == null || s.length() < t.length() || s.length() == 0){\n re
three_thousand_world
NORMAL
2015-08-11T19:49:32+00:00
2018-10-27T04:37:26.563066+00:00
92,467
false
public class Solution {\n public String minWindow(String s, String t) {\n if(s == null || s.length() < t.length() || s.length() == 0){\n return "";\n }\n HashMap<Character,Integer> map = new HashMap<Character,Integer>();\n for(char c : t.toCharArray()){\n if(map....
273
7
[]
36
minimum-window-substring
Why you failed the last test case: An interesting bug when I used two HashMaps in Java
why-you-failed-the-last-test-case-an-int-qet0
The logic of my code is just as most other people, to use two HashMap to count t and s. \nI encountered an interesting bug. The code is as following:\n\n\npubli
lajizaijian
NORMAL
2019-03-31T19:17:03.096144+00:00
2019-08-18T01:07:02.546293+00:00
7,518
false
The logic of my code is just as most other people, to use two HashMap to count t and s. \nI encountered an interesting bug. The code is as following:\n```\n\npublic String minWindow(String s, String t) {\n char[] ss = s.toCharArray();\n char[] tt = t.toCharArray();\n Map<Character, Integer> map_s =...
201
0
[]
43
minimum-window-substring
16ms simple and neat c++ solution only using a vector. Detailed explanation
16ms-simple-and-neat-c-solution-only-usi-rqia
Initialize a vector called remaining, which contains the needed\n matching numbers of each character in s. \n 2. If there are still\n characters neede
ztchf
NORMAL
2015-07-06T20:46:47+00:00
2018-08-27T05:37:41.101205+00:00
35,686
false
1. Initialize a vector called `remaining`, which contains the needed\n matching numbers of each character in `s`. \n 2. If there are still\n characters needed to be contained (increment `i` in this case),\n decrease the matching number of that character and check if it is\n still non-negative. ...
187
4
[]
14
minimum-window-substring
Python two pointer sliding window with explanation
python-two-pointer-sliding-window-with-e-eq8w
The idea is we use a variable-length sliding window which is gradually applied across the string. We use two pointers: start and end to mark the sliding window.
rarara
NORMAL
2019-01-27T08:27:41.300218+00:00
2023-12-11T20:59:17.414998+00:00
23,574
false
The idea is we use a variable-length sliding window which is gradually applied across the string. We use two pointers: start and end to mark the sliding window. We start by fixing the start pointer and moving the end pointer to the right. The way we determine the current window is a valid one is by checking if all the...
178
1
[]
27
minimum-window-substring
Sharing my straightforward O(n) solution with explanation
sharing-my-straightforward-on-solution-w-0d5s
string minWindow(string S, string T) {\n string result;\n if(S.empty() || T.empty()){\n return result;\n }\n unordered_ma
zxyperfect
NORMAL
2014-12-14T21:10:59+00:00
2014-12-14T21:10:59+00:00
56,791
false
string minWindow(string S, string T) {\n string result;\n if(S.empty() || T.empty()){\n return result;\n }\n unordered_map<char, int> map;\n unordered_map<char, int> window;\n for(int i = 0; i < T.length(); i++){\n map[T[i]]++;\n }\n int ...
139
4
['Hash Table', 'Two Pointers', 'C++']
19
minimum-window-substring
Simple Python sliding window solution with detailed explanation
simple-python-sliding-window-solution-wi-lp98
\nfrom collections import Counter\n\nclass Solution:\n def minWindow(self, s: str, t: str) -> str:\n \'\'\'\n Keep t_counter of char counts in
gins1
NORMAL
2020-12-11T20:17:49.666774+00:00
2020-12-11T20:20:31.731418+00:00
21,066
false
```\nfrom collections import Counter\n\nclass Solution:\n def minWindow(self, s: str, t: str) -> str:\n \'\'\'\n Keep t_counter of char counts in t\n \n We make a sliding window across s, tracking the char counts in s_counter\n We keep track of matches, the number of chars with mat...
134
1
['Sliding Window', 'Python', 'Python3']
10
minimum-window-substring
Accepted O(n) solution
accepted-on-solution-by-heleifz-j255
class Solution {\n public:\n string minWindow(string S, string T) {\n if (S.empty() || T.empty())\n {\n return ""
heleifz
NORMAL
2014-09-03T17:23:59+00:00
2018-09-22T02:42:58.968651+00:00
89,338
false
class Solution {\n public:\n string minWindow(string S, string T) {\n if (S.empty() || T.empty())\n {\n return "";\n }\n int count = T.size();\n int require[128] = {0};\n bool chSet[128] = {false};\n for (int i = 0...
116
4
[]
27