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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
minimum-moves-to-move-a-box-to-their-target-location | [C++] Accepted, Clear solution to understand for this long problem with proper variable names | c-accepted-clear-solution-to-understand-cvlcr | \nclass Solution {\npublic:\n int n , m;\n int dx[4] = {1, 0, -1, 0};\n int dy[4] = {0, 1, 0, -1};\n\t\n bool inside(int x, int y) {\n return | vaibhav15 | NORMAL | 2021-06-11T14:52:55.699047+00:00 | 2021-06-11T14:52:55.699094+00:00 | 2,154 | false | ```\nclass Solution {\npublic:\n int n , m;\n int dx[4] = {1, 0, -1, 0};\n int dy[4] = {0, 1, 0, -1};\n\t\n bool inside(int x, int y) {\n return (x >= 0 && x < n && y >= 0 && y < m);\n }\n\n bool canWalk(int srcX, int srcY, int destX, int destY, vector<vector<char>>&grid, vector<vector<int>>&vi... | 34 | 2 | [] | 7 |
minimum-moves-to-move-a-box-to-their-target-location | Python Straightforward 2-stage BFS, Explained | python-straightforward-2-stage-bfs-expla-vw2l | First define a function to check from current state, what are the possible neighbouring states (use BFS to check if we can move the player to required location) | davyjing | NORMAL | 2019-11-17T04:04:05.043235+00:00 | 2019-11-18T19:45:52.408779+00:00 | 4,672 | false | First define a function to check from current state, what are the possible neighbouring states (use BFS to check if we can move the player to required location). Notice that the state includes both the location of the box and the player.\nSecond BFS to see if we can reach the target location.\n```\nclass Solution:\n ... | 25 | 1 | [] | 5 |
minimum-moves-to-move-a-box-to-their-target-location | Fast easy to understand solution using 2 BFSs [intuition+diagram+explanation] | fast-easy-to-understand-solution-using-2-9mro | Little improvisation of the solution provided by sguo-lq, and also explaining every step and the intuition for the approach.\n\nDon\'t panic by seeing the lengt | coderangshu | NORMAL | 2021-09-18T20:31:33.928147+00:00 | 2022-10-12T04:43:53.920935+00:00 | 1,232 | false | Little improvisation of the solution provided by [sguo-lq](https://leetcode.com/problems/minimum-moves-to-move-a-box-to-their-target-location/discuss/432593/cpp-two-bfs-solution-8ms-beat-100), and also explaining every step and the intuition for the approach.\n\n**Don\'t panic by seeing the length of the solution it is... | 22 | 0 | [] | 3 |
minimum-moves-to-move-a-box-to-their-target-location | [Java] BFS (17ms), Explained with comments | java-bfs-17ms-explained-with-comments-by-9fy4 | Two things need to pay attention:\n While trying to recorded to visited position of Box, we need to include an additional dimension to record which direction th | lucas_zhc | NORMAL | 2019-11-18T00:37:57.776201+00:00 | 2019-12-03T18:24:27.323563+00:00 | 2,967 | false | Two things need to pay attention:\n* While trying to recorded to **visited position of Box**, we need to include an additional dimension to record which direction the Player pushed the box from. For example, there are 4 previous positions that the Box can arrive position (x, y). We have to treat those 4 states separate... | 20 | 0 | ['Breadth-First Search', 'Java'] | 1 |
minimum-moves-to-move-a-box-to-their-target-location | [cpp] BFS + DFS solution | cpp-bfs-dfs-solution-by-insomniacat-v6xr | Use BFS to solve the problem:\nFor each state [person, box], use dfs to find if the person can walk to the \'back\' of the box and push the box. Once the box | insomniacat | NORMAL | 2019-11-17T04:25:54.905143+00:00 | 2020-09-06T05:55:47.230992+00:00 | 2,089 | false | Use BFS to solve the problem:\nFor each state `[person, box]`, use dfs to find if the person can walk to the \'back\' of the box and push the box. Once the box reaches the destination, bfs guarantees to find the optimal solution.\nBe careful with the box position since we may be obstructed by the box after we push it... | 15 | 1 | [] | 7 |
minimum-moves-to-move-a-box-to-their-target-location | [C++ 16ms/12MB]Pictures to show step-by-step problem solving | c-16ms12mbpictures-to-show-step-by-step-ltho3 | At the first sight of this problem, I was trying to use backtracking or recursion to solve until I reread the question and examples: even there is a valid path | dennysun | NORMAL | 2021-09-29T09:08:35.896119+00:00 | 2021-09-29T09:08:35.896160+00:00 | 990 | false | At the first sight of this problem, I was trying to use backtracking or recursion to solve until I reread the question and examples: even there is a valid path from box position to target position the player could still be not able to make it. Then I gave up recursion also considering it can end up with O(4^(mn)) in wo... | 14 | 1 | [] | 3 |
minimum-moves-to-move-a-box-to-their-target-location | c++, 2 * BFS with explanations | c-2-bfs-with-explanations-by-savvadia-1jq2 | Intuition and observations:\n we need to count only the box moves, so let\'s kick around the box and count the moves\n for the person we need to check if he can | savvadia | NORMAL | 2019-11-27T07:49:21.607184+00:00 | 2019-11-27T07:50:18.150334+00:00 | 1,139 | false | Intuition and observations:\n* we need to count only the box moves, so let\'s kick around the box and count the moves\n* for the person we need to check if he can walk to the place in front of the box\n* to move the box, the person have to stand in front of it:\n```\n[[".",".","."], [[".",".","."], [[".","S","."], [... | 11 | 1 | ['Breadth-First Search'] | 2 |
minimum-moves-to-move-a-box-to-their-target-location | [Python] Level-by-level BFS solution (similar problems listed) | python-level-by-level-bfs-solution-simil-9nog | Level-by-level BFS visit can be used to solve a lot of problems of finding discrete shortest distance.\nPlease see and vote for my solutions for these similar p | otoc | NORMAL | 2019-11-17T04:22:58.930413+00:00 | 2022-07-30T23:59:49.103044+00:00 | 1,826 | false | Level-by-level BFS visit can be used to solve a lot of problems of finding discrete shortest distance.\nPlease see and vote for my solutions for these similar problems\n[102. Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal/discuss/1651394/Python-level-by-level-BFS-Solu... | 10 | 1 | [] | 2 |
minimum-moves-to-move-a-box-to-their-target-location | Two BFS for player and box - beats 100 % | two-bfs-for-player-and-box-beats-100-by-7r83o | \npublic class Solution \n{\n private int[] x = new int[4] { 0, 0, 1, -1 };\n private int[] y = new int[4] { 1, -1, 0, 0 };\n \n public int MinPushB | srithar | NORMAL | 2020-02-05T02:21:02.178427+00:00 | 2020-02-05T02:21:02.178513+00:00 | 1,139 | false | ```\npublic class Solution \n{\n private int[] x = new int[4] { 0, 0, 1, -1 };\n private int[] y = new int[4] { 1, -1, 0, 0 };\n \n public int MinPushBox(char[][] grid) \n {\n int bx = 0, by = 0, px = 0, py = 0, tx = 0, ty = 0;\n \n int m = grid.Length;\n int n = grid[0].Lengt... | 8 | 1 | [] | 5 |
minimum-moves-to-move-a-box-to-their-target-location | Python 3 - 2 BFS clean code | python-3-2-bfs-clean-code-by-yunqu-8kaz | For each push, make sure the person can stand at the required location that is reachable from a previous standing location.\n\npython\nclass Solution:\n def | yunqu | NORMAL | 2021-03-26T22:35:48.154537+00:00 | 2021-03-26T22:35:48.154567+00:00 | 425 | false | For each push, make sure the person can stand at the required location that is reachable from a previous standing location.\n\n```python\nclass Solution:\n def minPushBox(self, grid: List[List[str]]) -> int:\n m, n = len(grid), len(grid[0])\n for i in range(m):\n for j in range(n):\n ... | 5 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | [55 Lines] [challenge me] Possible shortest C++ solution | 55-lines-challenge-me-possible-shortest-59zwu | Python is always my envy to be able to write short code.\nAfter I picked up some more knolwedge about C++, I can also write some code comparable with python in | codedayday | NORMAL | 2020-05-13T06:37:48.475542+00:00 | 2020-05-14T03:36:33.617135+00:00 | 742 | false | Python is always my envy to be able to write short code.\nAfter I picked up some more knolwedge about C++, I can also write some code comparable with python in terms of length.\nIf you can help me make it shorter, I will highly apprecitate. \n\nActually, in terms of space cost, this solution is also competitive. But I ... | 5 | 1 | ['Depth-First Search', 'Breadth-First Search', 'C'] | 2 |
minimum-moves-to-move-a-box-to-their-target-location | [Java] BFS + DFS with explanation | java-bfs-dfs-with-explanation-by-lnbyk-o7rd | The idea is using BFS find the shortest path from the box location to the destination.\nHowever, each time we check if the box can be moved we need to check 2 p | lnbyk | NORMAL | 2019-11-24T02:44:06.183407+00:00 | 2019-11-24T02:44:06.183464+00:00 | 903 | false | The idea is using BFS find the shortest path from the box location to the destination.\nHowever, each time we check if the box can be moved we need to check 2 position\n\n\nThe Box is just the box and the cycle is the position we need check\nWhen we ... | 5 | 1 | [] | 3 |
minimum-moves-to-move-a-box-to-their-target-location | Java Deque bfs | java-deque-bfs-by-gcl272633743-bc20 | \nclass Solution {\n /**\n \u8FD9\u4E2A\u9898\u76EE\u4E0D\u540C\u4E8E\u4EE5\u524D\u7684bfs, \u56E0\u4E3A\u4EBA\u8981\u63A8\u7740\u7BB1\u5B50\u8D70\uFF0C\ | gcl272633743 | NORMAL | 2021-06-14T03:30:26.387652+00:00 | 2021-06-14T03:30:26.387682+00:00 | 476 | false | ```\nclass Solution {\n /**\n \u8FD9\u4E2A\u9898\u76EE\u4E0D\u540C\u4E8E\u4EE5\u524D\u7684bfs, \u56E0\u4E3A\u4EBA\u8981\u63A8\u7740\u7BB1\u5B50\u8D70\uFF0C\u6240\u6709\u4EBA\u548C\u7BB1\u5B50\u7684\u5750\u6807\u8054\u5408\u8D77\u6765\u4F5C\u4E3Abfs\u7684\u5750\u6807\n [bx][by][px][py]\n\n \u884D\u751F\u5... | 4 | 0 | ['Breadth-First Search', 'Queue', 'Java'] | 2 |
minimum-moves-to-move-a-box-to-their-target-location | [Python] 0-1 BFS with comments and explanation | python-0-1-bfs-with-comments-and-explana-p65c | Each node in our graph will contain state of box, person and the minimum cost to reach it.\n- We do a 0-1 BFS where 0 is the cost between vertices where a perso | bharadwaj6 | NORMAL | 2020-03-02T10:22:10.811261+00:00 | 2020-03-02T10:39:25.884507+00:00 | 795 | false | - Each node in our graph will contain state of box, person and the minimum cost to reach it.\n- We do a 0-1 BFS where 0 is the cost between vertices where a person can reach without having to move the box, and 1 is the cost between vertices where box moved.\n- For more explanation on 0-1 BFS, watch [this video](https:/... | 4 | 0 | ['Breadth-First Search', 'Python3'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | [Python3] A* - Simple | python3-a-simple-by-dolong2110-h9fo | 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 | dolong2110 | NORMAL | 2024-03-24T16:22:17.206200+00:00 | 2024-03-24T16:22:17.206233+00:00 | 240 | 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 | ['Breadth-First Search', 'Heap (Priority Queue)', 'Python3'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | JAVE intuitive BFS solution | jave-intuitive-bfs-solution-by-guiguia-jbsc | Two BFS. \n1st BFS to push box as regular BFS. \n2nd BFS to check if the person can reach the box inside 1st BFS\n\nBFS to push box. For each positon of box, ch | guiguia | NORMAL | 2021-08-22T00:08:43.708854+00:00 | 2021-08-22T00:08:43.708891+00:00 | 367 | false | Two BFS. \n1st BFS to push box as regular BFS. \n*2nd BFS to check if the person can reach the box inside 1st BFS\n\nBFS to push box. For each positon of box, check if player can push it.\nBox can be pushed only when it has two opposite adajacent grids are empty\n\t1. traverse the grid to find the location of player, b... | 3 | 0 | [] | 1 |
minimum-moves-to-move-a-box-to-their-target-location | Java | BFS + BFS | java-bfs-bfs-by-smartyvibhuse-cdru | \nclass Solution {\n // Up, Right, Bottom & Left\n private int[][] dir = new int[][]{{0, 1}, {1, 0}, {0, -1}, {-1, 0 | smartyvibhuse | NORMAL | 2021-06-28T12:44:26.454163+00:00 | 2021-06-28T12:44:26.454248+00:00 | 454 | false | ```\nclass Solution {\n // Up, Right, Bottom & Left\n private int[][] dir = new int[][]{{0, 1}, {1, 0}, {0, -1}, {-1, 0}};\n \n public int minPushBox(char[][] grid) {\n int step = 0;\n int m = grid.length;\n int n = grid[0].length;\n Queue<in... | 3 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Simple to Understand Java solution | simple-to-understand-java-solution-by-us-qh6z | \nclass Solution {\n \n /**\n \n 1. Find the start , box and target cordinate .\n \n 2. Then using Start Cordinate start BFS . Create No | user5958h | NORMAL | 2021-06-11T15:08:31.301454+00:00 | 2021-06-11T15:08:31.301501+00:00 | 918 | false | ```\nclass Solution {\n \n /**\n \n 1. Find the start , box and target cordinate .\n \n 2. Then using Start Cordinate start BFS . Create Normal Visted set \n \n 3. There will be 3 Possibilities :\n \n 3.1 You find the Target , return whateevr No of Moves you have do... | 3 | 0 | ['Java'] | 5 |
minimum-moves-to-move-a-box-to-their-target-location | python bfs code with explanation | python-bfs-code-with-explanation-by-yiyu-qbii | To push a box, we need two steps\n- Check whether we could go to the neighbor cell of the box. Also the opposite side of this neighbor cell should be empty. Oth | yiyue15 | NORMAL | 2019-11-20T11:01:49.428428+00:00 | 2019-11-20T11:01:49.428459+00:00 | 394 | false | To push a box, we need two steps\n- Check whether we could go to the neighbor cell of the box. Also the opposite side of this neighbor cell should be empty. Otherwise there is no point moving there.\n\t- E.g. `.B.` has two neighbor cells which we could check whether we could move there\n\t- `#B.` won\'t be checked. Alt... | 3 | 0 | [] | 1 |
minimum-moves-to-move-a-box-to-their-target-location | C++ Solution. Using Dijkstra's Algorithm | c-solution-using-dijkstras-algorithm-by-ql4a1 | Intuition\nUse Dijkstra\'s Algorithm\n\n# Code\n\nclass Solution {\npublic:\n // 0 - distance\n // 1 - BoxX\n // 2 - BoxY\n // 3 - ManX\n // 4 - | pulkitgupta38 | NORMAL | 2023-08-02T12:41:52.078266+00:00 | 2023-08-02T12:47:41.202430+00:00 | 556 | false | # Intuition\nUse Dijkstra\'s Algorithm\n\n# Code\n```\nclass Solution {\npublic:\n // 0 - distance\n // 1 - BoxX\n // 2 - BoxY\n // 3 - ManX\n // 4 - ManY\n\n int dx[4] = {0, 0, -1, 1};\n int dy[4] = {-1, 1, 0, 0};\n\n bool isValid(int x, int y, int n, int m, vector<vector<char>> &grid){\n ... | 2 | 0 | ['Array', 'Breadth-First Search', 'Graph', 'Heap (Priority Queue)', 'Matrix', 'Shortest Path', 'C++'] | 1 |
minimum-moves-to-move-a-box-to-their-target-location | c++ | easy | short | c-easy-short-by-venomhighs7-w14t | \n# Code\n\nclass Solution {\npublic:\n int n , m;\n int dx[4] = {1, 0, -1, 0};\n int dy[4] = {0, 1, 0, -1};\n\t\n bool inside(int x, int y) {\n | venomhighs7 | NORMAL | 2022-10-19T01:49:14.877486+00:00 | 2022-10-19T01:49:14.877521+00:00 | 732 | false | \n# Code\n```\nclass Solution {\npublic:\n int n , m;\n int dx[4] = {1, 0, -1, 0};\n int dy[4] = {0, 1, 0, -1};\n\t\n bool inside(int x, int y) {\n return (x >= 0 && x < n && y >= 0 && y < m);\n }\n\n bool canWalk(int srcX, int srcY, int destX, int destY, vector<vector<char>>&grid, vector<vect... | 2 | 0 | ['C++'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | [Golang] A-Star | golang-a-star-by-vasakris-h3z7 | \ntype State struct {\n Box []int\n Person []int\n TotalDistanceToTarget int\n DistanceToBox int\n Moves int\n}\n\nfunc minPushBox(grid [][]byte) | vasakris | NORMAL | 2022-10-01T20:33:25.327055+00:00 | 2022-11-29T17:17:25.703714+00:00 | 185 | false | ```\ntype State struct {\n Box []int\n Person []int\n TotalDistanceToTarget int\n DistanceToBox int\n Moves int\n}\n\nfunc minPushBox(grid [][]byte) int {\n m := len(grid)\n n := len(grid[0])\n \n visited := make(map[string]bool)\n var target, box, person []int\n for r := 0; r < m; r++ ... | 2 | 0 | ['Go'] | 1 |
minimum-moves-to-move-a-box-to-their-target-location | C++| BFS | O((m*n)^2) | c-bfs-omn2-by-kumarabhi98-0yad | This problem, is not too Hard. Just Think of brute force solution and apply BFS.\nWhat are the conditions to move from one cell to Another?\nLet\'s assume that | kumarabhi98 | NORMAL | 2022-04-12T15:08:52.807666+00:00 | 2022-04-12T15:08:52.807706+00:00 | 175 | false | This problem, is not too Hard. Just Think of brute force solution and apply BFS.\n**What are the conditions to move from one cell to Another?**\nLet\'s assume that current position of Box is **[i,j]**.\n* If We want to move box to [i+1,j] then this cell should\'nt contain any wall and player should be able to come to c... | 2 | 0 | ['Breadth-First Search', 'C'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Python Dijkstra (player and box coordinates - state space) | python-dijkstra-player-and-box-coordinat-u54l | If state space (vertices of a graph) represented as player and box coordinates, and the edges have value 1 if during state transition we pushed the box, 0 other | 404akhan | NORMAL | 2021-11-10T13:45:09.751738+00:00 | 2021-11-10T13:45:09.751770+00:00 | 254 | false | If state space (vertices of a graph) represented as player and box coordinates, and the edges have value 1 if during state transition we pushed the box, 0 otherwise. Given this formulation we can run Dijkstra algorithm to find minimum number of pushes to get box to the target.\n\n```\nfrom sortedcontainers import Sorte... | 2 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | 10 ms solution, BFS with some comments | 10-ms-solution-bfs-with-some-comments-by-3u52 | \nclass Solution {\n public int minPushBox(char[][] grid) {\n if(grid == null)\n return 0;\n \n int row = grid.length;\n | ssgurpreetsingh | NORMAL | 2021-10-08T05:33:18.772085+00:00 | 2021-10-08T05:33:18.772132+00:00 | 498 | false | ```\nclass Solution {\n public int minPushBox(char[][] grid) {\n if(grid == null)\n return 0;\n \n int row = grid.length;\n int col = grid[0].length;\n int[] target = null;\n int[] box = null;\n int[] player = null;\n \n for(int i=0; i < row; ... | 2 | 0 | [] | 2 |
minimum-moves-to-move-a-box-to-their-target-location | Super clean Java code | super-clean-java-code-by-kshittiz-hjce | \nclass Solution {\n int n, m;\n char[][] grid;\n int[][] dirs = new int[][] {\n {1, 0}, {0, 1}, {-1, 0}, {0, -1}\n };\n public int minPus | kshittiz | NORMAL | 2021-09-19T08:11:07.897554+00:00 | 2021-09-19T08:11:07.897581+00:00 | 343 | false | ```\nclass Solution {\n int n, m;\n char[][] grid;\n int[][] dirs = new int[][] {\n {1, 0}, {0, 1}, {-1, 0}, {0, -1}\n };\n public int minPushBox(char[][] grid) {\n n = grid.length;\n m = grid[0].length;\n this.grid = grid;\n int[] box = new int[2], target = new int[2],... | 2 | 0 | [] | 1 |
minimum-moves-to-move-a-box-to-their-target-location | C# clean & easy to understand | c-clean-easy-to-understand-by-showwhite-xfot | \n //{\'#\',\'.\',\'.\',\'.\'}\n //{\'.\',\'.\',\'S\',\'.\'}\n //{\'.\',\'B\',\'.\',\'T\'}\n //{\'.\',\'.\',\'.\',\'#\'}\n //We can start from th | showwhite | NORMAL | 2021-07-30T06:14:55.268162+00:00 | 2021-07-30T06:14:55.268201+00:00 | 186 | false | \n //{\'#\',\'.\',\'.\',\'.\'}\n //{\'.\',\'.\',\'S\',\'.\'}\n //{\'.\',\'B\',\'.\',\'T\'}\n //{\'.\',\'.\',\'.\',\'#\'}\n //We can start from the current Box location & do a BFS.\n //We don\'t really need to move player, we can just simulate it.\n //In each level, we can try to find valid position... | 2 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Can player walk through target cell because its an empty cell? | can-player-walk-through-target-cell-beca-hyfc | The following is possible only if the player can walk through Target. Why doesn\'t the problem mention this? Is this a test of something in an actual interview? | RockyTheAlienSpider | NORMAL | 2021-07-21T12:26:22.496512+00:00 | 2021-07-21T12:26:22.496554+00:00 | 119 | false | The following is possible only if the player can walk through Target. Why doesn\'t the problem mention this? Is this a test of *something* in an actual interview? \n\n```\n\nExample 3:\n\nInput: grid = [["#","#","#","#","#","#"],\n ["#","T",".",".","#","#"],\n ["#",".","#","B",".","#"],\n ... | 2 | 0 | [] | 1 |
minimum-moves-to-move-a-box-to-their-target-location | [C++] BFS with deque | c-bfs-with-deque-by-tianchunh97-rhvm | 0-1 BFS implemented by deque: when the new state pushes the box, push it to the back of the deque; otherwise push front. In this way, every node we pop from the | tianchunh97 | NORMAL | 2020-09-13T04:02:36.706607+00:00 | 2020-09-13T04:02:36.706647+00:00 | 231 | false | 0-1 BFS implemented by deque: when the new state pushes the box, push it to the back of the deque; otherwise push front. In this way, every node we pop from the deque has the smallest number of pushes in the deque.\n\nPriority queue can also be used instead of deque. My results for both methods:\ndeque: 120ms 16MB\npri... | 2 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | [JAVA] BFS with comments | java-bfs-with-comments-by-magiciendecode-jbrr | visited array is 3 dimentional, box x,y index and last move direction.\n2. as we have 4 direcitons, when ierate, just use index as direction.\n3. for each next | magiciendecode | NORMAL | 2020-08-15T23:38:19.871615+00:00 | 2020-08-15T23:38:19.871646+00:00 | 498 | false | 1. visited array is 3 dimentional, box x,y index and last move direction.\n2. as we have 4 direcitons, when ierate, just use index as direction.\n3. for each next move, we need to check next box position and next player position is in bound.\n4. an additional bfs function to check the player can mvoe the target player ... | 2 | 0 | ['Breadth-First Search', 'Java'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Simple Java Solution -- Union Find & BFS | simple-java-solution-union-find-bfs-by-r-qhh5 | \nclass Solution {\n //1. \u5E76\u67E5\u96C6\u5224\u65AD\u80FD\u5426\u5230\u8FBE\n //2. BFS \u7BB1\u5B50\n int[][] dir = new int[][]{{-1, 0}, {1, 0}, { | renyajie | NORMAL | 2020-01-23T06:58:01.269329+00:00 | 2020-01-23T06:58:01.269362+00:00 | 244 | false | ```\nclass Solution {\n //1. \u5E76\u67E5\u96C6\u5224\u65AD\u80FD\u5426\u5230\u8FBE\n //2. BFS \u7BB1\u5B50\n int[][] dir = new int[][]{{-1, 0}, {1, 0}, {0, 1}, {0, -1}};\n public int minPushBox(char[][] grid) {\n int m = grid.length, n = grid[0].length;\n int px = 0, py = 0, tx = 0, ty = 0, b... | 2 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | C# Readable BFS + BFS with inline comments | c-readable-bfs-bfs-with-inline-comments-8wzkm | \npublic class Solution {\n private char[][] grid;\n private Position boxPosition;\n private int[] directions = new int[] {0, 1, 0, -1, 0};\n \n | mmikhail | NORMAL | 2019-11-25T20:29:47.926142+00:00 | 2019-11-25T20:29:47.926193+00:00 | 215 | false | ```\npublic class Solution {\n private char[][] grid;\n private Position boxPosition;\n private int[] directions = new int[] {0, 1, 0, -1, 0};\n \n // Represents coordinate with Equals() implemented by default for Queues\n public struct Position\n {\n public int X;\n public int Y;\n ... | 2 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | non-nested BFS with O(1) connectivity check | non-nested-bfs-with-o1-connectivity-chec-g0c0 | Up to now all these solutions here contain nested BFS/DFS/Union inside the outer BFS to check if the person can reach certain position. However, this can be don | 617280219 | NORMAL | 2019-11-20T11:10:08.970486+00:00 | 2019-11-20T11:10:08.970516+00:00 | 200 | false | Up to now all these solutions here contain nested BFS/DFS/Union inside the outer BFS to check if the person can reach certain position. However, this can be done in O(1) time with some preprocessing.\nNotice that after the first push, we only need to consider states with the person next to the box. In that case, we onl... | 2 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | ✅ 2 BFS | Easy to understand | 75% TC | 80% SC | 2-bfs-easy-to-understand-75-tc-80-sc-by-5hyh0 | Intuition\n1. If the box is just sitting with robotic wheels, if we want to move to target, it is a simple problem, we can just use BFS to find the shortest rou | gregor_98 | NORMAL | 2024-12-01T17:13:26.651216+00:00 | 2024-12-01T17:13:26.651244+00:00 | 49 | false | # Intuition\n1. If the box is just sitting with robotic wheels, if we want to move to target, it is a simple problem, we can just use BFS to find the shortest route to the target (simple right, we should work on robotic wheels \uD83D\uDE1B)\n2. Now lets introduce the constraint that the person need to be standing behin... | 1 | 0 | ['C++'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | BFS with a heap | bfs-with-a-heap-by-maxorgus-2i5g | Note normal bfs can lead to wrong answers, since the number of pushes of which we wish to find the minimum is not necessarily increasing in the normal queue whe | MaxOrgus | NORMAL | 2024-01-15T02:09:26.988387+00:00 | 2024-01-15T02:09:26.988405+00:00 | 102 | false | Note normal bfs can lead to wrong answers, since the number of pushes of which we wish to find the minimum is not necessarily increasing in the normal queue where the step counts corresponds to, rather, the moves of the player, which include steps that are not pushes. So we need to restructure the queue using a heap to... | 1 | 0 | ['Breadth-First Search', 'Heap (Priority Queue)', 'Python3'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Single BFS || Priority queue || Intuitive Solution | single-bfs-priority-queue-intuitive-solu-s85z | \n\nclass Solution {\npublic:\n\nint dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};\nint dp[22][22][22][22],vis[22][22][22][22];\nint ti,tj;\nbool check(int i,int j,ve | princegup678 | NORMAL | 2023-10-04T17:20:09.645089+00:00 | 2023-10-04T17:20:31.001008+00:00 | 39 | false | \n```\nclass Solution {\npublic:\n\nint dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};\nint dp[22][22][22][22],vis[22][22][22][22];\nint ti,tj;\nbool check(int i,int j,vector<vector<char>>& grid){\n int n=grid.size(),m=grid[0].size();\n if(i<0 || i>=n ||j<0|| j>=m || grid[i][j]==\'#\') return false;\n return true;\n... | 1 | 0 | ['C++'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | O(n*m) solution using Tarjan to precauculate biconnected component | onm-solution-using-tarjan-to-precauculat-ye33 | Approach\nBefore we start, I need to mention, this is definately not an answer interviewer expects you to implement. Feel free to ignore this solution if you ar | t3cmax | NORMAL | 2023-06-22T10:02:36.920596+00:00 | 2023-06-22T11:01:10.995969+00:00 | 100 | false | # Approach\nBefore we start, I need to mention, this is definately not an answer interviewer expects you to implement. Feel free to ignore this solution if you are just preparing for interview. They are not hiring you to paticipate coding competition.\n\nI shared this solution just want to give some inspiration to thos... | 1 | 0 | ['Biconnected Component', 'C++'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | standard BFS Approach solution ,clean Code ,BFS*BFS | standard-bfs-approach-solution-clean-cod-sfeg | Intuition\nwe use BFS to find minimum distance \n\n# Approach\nBFS * BFS\n# Complexity\n- Time complexity:\nO(n^2 * m^2) \n\n- Space complexity:\n O(n^2 * m^2) | latecoder001 | NORMAL | 2023-04-04T15:31:37.218812+00:00 | 2023-04-04T15:31:37.218850+00:00 | 99 | false | # Intuition\nwe use BFS to find minimum distance \n\n# Approach\nBFS * BFS\n# Complexity\n- Time complexity:\n$$O(n^2 * m^2)$$ \n\n- Space complexity:\n $$O(n^2 * m^2)$$ \n\n# Code\n```\nclass Solution {\npublic:\nint dx[4]={0,0,1,-1};\nint dy[4]={1,-1,0,0};\nint m,n;\n\nbool check(int x,int y,vector<vector<char>>& gri... | 1 | 0 | ['C++'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | [C#] BFS + Top-down DP (explained) | c-bfs-top-down-dp-explained-by-sh0wmet3h-enz1 | Intuition\nPorted from C++: [1] https://leetcode.com/problems/minimum-moves-to-move-a-box-to-their-target-location/solutions/431144/cpp-bfs-dfs-solution/\n# BFS | sh0wMet3hC0de | NORMAL | 2022-12-03T02:47:39.692643+00:00 | 2022-12-03T02:48:10.671137+00:00 | 65 | false | # Intuition\nPorted from C++: [1] https://leetcode.com/problems/minimum-moves-to-move-a-box-to-their-target-location/solutions/431144/cpp-bfs-dfs-solution/\n# BFS\nFirst we sweep the given grid for finding and storing the locations of the person, the box and the target.\nNext we initialize a queue and a hashSet with th... | 1 | 0 | ['Depth-First Search', 'Breadth-First Search', 'C#'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | All edge cases: | all-edge-cases-by-anujjadhav-2knc | There are many great solutions available for this post, here I will only focus on the edge cases where your code may go wrong.\n\nI will highly suggest to give | AnujJadhav | NORMAL | 2022-09-06T21:11:55.788893+00:00 | 2022-09-06T21:12:41.161684+00:00 | 163 | false | There are many great solutions available for this post, here I will only focus on the edge cases where your code may go wrong.\n\nI will highly suggest to give it a try first otherwise this will ruin your experience \u2639\uFE0F.\n\nImp edge cases:\n\n1. Check whether there exists a path from person till the pos from w... | 1 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | [Python 3] 0-1 BFS clean code | python-3-0-1-bfs-clean-code-by-gabhay-aa2q | \tclass Solution:\n\t\tdef minPushBox(self, grid: List[List[str]]) -> int:\n\t\t\tn,m=len(grid),len(grid[0])\n\t\t\tfor i in range(n):\n\t\t\t\tfor j in range(m | gabhay | NORMAL | 2022-08-08T12:53:53.939096+00:00 | 2022-08-08T12:56:32.211336+00:00 | 332 | false | \tclass Solution:\n\t\tdef minPushBox(self, grid: List[List[str]]) -> int:\n\t\t\tn,m=len(grid),len(grid[0])\n\t\t\tfor i in range(n):\n\t\t\t\tfor j in range(m):\n\t\t\t\t\tif grid[i][j]==\'S\':\n\t\t\t\t\t\tplayer=[i,j]\n\t\t\t\t\telif grid[i][j]==\'T\':\n\t\t\t\t\t\ttarget=[i,j]\n\t\t\t\t\telif grid[i][j]==\'B\':\n\... | 1 | 0 | ['Breadth-First Search', 'Python3'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Python Double BFS | python-double-bfs-by-akli64-pmqi | \nfrom collections import deque\n\nclass Solution:\n def minPushBox(self, grid: List[List[str]]) -> int:\n \n in_bounds = lambda grid, i, j : 0 | akli64 | NORMAL | 2022-04-20T06:49:38.981260+00:00 | 2022-04-20T06:49:38.981298+00:00 | 121 | false | ```\nfrom collections import deque\n\nclass Solution:\n def minPushBox(self, grid: List[List[str]]) -> int:\n \n in_bounds = lambda grid, i, j : 0 <= i < len(grid) and 0 <= j < len(grid[0])\n \n dirs = [\n (1, 0),\n (-1, 0),\n (0, 1),\n (0, -1)\... | 1 | 0 | [] | 1 |
minimum-moves-to-move-a-box-to-their-target-location | C++ | Easy implementation | BFS*BFS | Clean code | c-easy-implementation-bfsbfs-clean-code-rxfkz | \nclass Solution {\npublic:\n int arr[4]= {0,0,1,-1};\n int brr[4]={1,-1,0,0};\n bool chk (vector<vector<char>>& grid, int reachx,int reachy,int bx,in | coz_its_raunak | NORMAL | 2022-02-01T17:38:39.603587+00:00 | 2022-02-01T17:38:39.603632+00:00 | 236 | false | ```\nclass Solution {\npublic:\n int arr[4]= {0,0,1,-1};\n int brr[4]={1,-1,0,0};\n bool chk (vector<vector<char>>& grid, int reachx,int reachy,int bx,int by,int sx,int sy)\n {\n \n int r = grid.size();\n int c = grid[0].size();\n vector<vector<int>>vis(r,vector<int>(c,-1));\n ... | 1 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | [Python] Solution with detailed thinking | python-solution-with-detailed-thinking-b-b1e1 | Background\nIn this problem, we are given a grid, there\'re 4 types of element:\n player - \'S\'\n box - \'B\'\n obstacle - \'#\'\n floor - \'.\'\n\nplayer need | bestbowenzhao | NORMAL | 2022-01-08T20:15:57.765618+00:00 | 2022-01-08T20:15:57.765652+00:00 | 531 | false | ### Background\nIn this problem, we are given a grid, there\'re 4 types of element:\n* player - \'S\'\n* box - \'B\'\n* obstacle - \'#\'\n* floor - \'.\'\n\nplayer need to push the box to the final target position, our target is to find the mininum push.\n\nThis is a variant of finding the shortest path from start to t... | 1 | 0 | ['Depth-First Search', 'Breadth-First Search', 'Python'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Java - BFS easy to understand solution | java-bfs-easy-to-understand-solution-by-u6zc7 | \nclass Solution {\n public int minPushBox(char[][] grid) {\n if (grid == null || grid.length == 0 || grid[0].length == 0) {\n return -1;\n | code_newbie | NORMAL | 2021-11-13T10:34:52.788894+00:00 | 2021-11-13T10:34:52.788934+00:00 | 423 | false | ```\nclass Solution {\n public int minPushBox(char[][] grid) {\n if (grid == null || grid.length == 0 || grid[0].length == 0) {\n return -1;\n }\n int[] box = new int[2];\n int[] player = new int[2];\n int[] target = new int[2];\n Map<String, Integer> steps = new ... | 1 | 0 | [] | 2 |
minimum-moves-to-move-a-box-to-their-target-location | Why the output is 5? | why-the-output-is-5-by-swetha96-zirg | grid = [["#","#","#","#","#","#"],\n ["#","T",".",".","#","#"],\n ["#",".","#","B",".","#"],\n ["#",".",".",".",".","# | swetha96 | NORMAL | 2021-11-11T04:43:02.414250+00:00 | 2021-11-11T04:43:02.414281+00:00 | 87 | false | grid = [["#","#","#","#","#","#"],\n ["#","T",".",".","#","#"],\n ["#",".","#","B",".","#"],\n ["#",".",".",".",".","#"],\n ["#",".",".",".","S","#"],\n ["#","#","#","#","#","#"]]\nOutput: 5\n\nFor the above testcase, why the output is 5, instead of ... | 1 | 0 | [] | 1 |
minimum-moves-to-move-a-box-to-their-target-location | c++ dijkstra + union find solution | c-dijkstra-union-find-solution-by-hanzho-2hqe | \nclass Solution {\npublic:\n int find(vector<int>& a, int i) {\n if(a[i] == i) {\n return i;\n }\n return a[i] = find(a, a[i | hanzhoutang | NORMAL | 2021-11-01T06:26:02.978465+00:00 | 2021-11-01T06:26:02.978516+00:00 | 216 | false | ```\nclass Solution {\npublic:\n int find(vector<int>& a, int i) {\n if(a[i] == i) {\n return i;\n }\n return a[i] = find(a, a[i]);\n }\n \n void merge(vector<int>& a, vector<int>& r, int i, int j) {\n int i_ = find(a,i);\n int j_ = find(a,j);\n if(i_ == ... | 1 | 0 | [] | 1 |
minimum-moves-to-move-a-box-to-their-target-location | BFS without using priority queue | O(m^2n^2) | clear explaination | Python | bfs-without-using-priority-queue-om2n2-c-kiq2 | We could reduce this problem to a shortest distance problem in graph:\n\nConstruct graph G = (V, E) as follows:\nLet vertice v denotes game state, a.k.a (player | flyneopolitan | NORMAL | 2021-10-02T20:43:45.861236+00:00 | 2021-10-02T20:46:10.798870+00:00 | 274 | false | We could reduce this problem to a shortest distance problem in graph:\n\nConstruct graph G = (V, E) as follows:\nLet vertice v denotes game state, a.k.a (player position, box position).\nLet edge e denotes change from one game state to another, so there are at most 4 edges for a vertex: player has at most 4 choices to ... | 1 | 0 | [] | 1 |
minimum-moves-to-move-a-box-to-their-target-location | Apply BFS twice - with some helpful hints | apply-bfs-twice-with-some-helpful-hints-9ppos | Algorithm:\n1. Choose the location of the box, \n2. Then, new person location should be opposite to that of the box.\n3. Then ask the algorithm - (can_reach def | ikna | NORMAL | 2021-08-22T19:16:25.142926+00:00 | 2021-08-22T19:16:25.142972+00:00 | 302 | false | **Algorithm**:\n1. Choose the location of the box, \n2. Then, new person location should be opposite to that of the box.\n3. Then ask the algorithm - (can_reach def) Can I reach to new_person from current person location? Only if the answer is \'yes\', consider that new box location.\n\n```\nclass Solution:\n def mi... | 1 | 0 | [] | 1 |
minimum-moves-to-move-a-box-to-their-target-location | BFS with (box,player) as state | bfs-with-boxplayer-as-state-by-simd_mmx-o2ad | This problem involves regular BFS with a few important distinctions.\n1. We cannot just directly look for shortest path from box to target. An additional condit | simd_mmx | NORMAL | 2021-07-20T16:17:33.272316+00:00 | 2021-07-20T16:22:36.163895+00:00 | 249 | false | This problem involves regular BFS with a few important distinctions.\n1. We cannot just directly look for shortest path from box to target. An additional condition is that the player should be able to reach the push_spot from where the box can be pushed. This extra condition needs to be checked at each step before cons... | 1 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Python BFS x 2 | python-bfs-x-2-by-fftnim-4xbt | ```py\nclass Solution:\n \n offsets = ((1, 0), (-1, 0), (0, 1), (0, -1))\n \n def minPushBox(self, grid: List[List[str]]) -> int:\n\n # check | fftnim | NORMAL | 2021-07-16T00:29:48.256995+00:00 | 2021-07-16T00:29:48.257034+00:00 | 142 | false | ```py\nclass Solution:\n \n offsets = ((1, 0), (-1, 0), (0, 1), (0, -1))\n \n def minPushBox(self, grid: List[List[str]]) -> int:\n\n # check if player can move from start to end given the ball\'s position\n def can_move(start, end, ball):\n if not (0 <= end[0] < rows and 0 <= end[1... | 1 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | [C++] BFS and DFS 80 lines | c-bfs-and-dfs-80-lines-by-yunqu-wc0b | I am trying to be as "clean-code" as possible.\n\ncpp\nclass Solution {\npublic:\n int dx[4] = {0, -1, 0, 1};\n int dy[4] = {-1, 0, 1, 0};\n int m, n;\ | yunqu | NORMAL | 2021-07-14T13:21:01.063812+00:00 | 2021-07-14T13:21:01.063855+00:00 | 210 | false | I am trying to be as "clean-code" as possible.\n\n```cpp\nclass Solution {\npublic:\n int dx[4] = {0, -1, 0, 1};\n int dy[4] = {-1, 0, 1, 0};\n int m, n;\n queue<vector<int>> q;\n unordered_set<string> seen1; // book-keeping worker and box locations\n unordered_set<string> seen2; // book-keeping for h... | 1 | 1 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Java A* Search | java-a-search-by-brucezu-xjk8 | \n /*\n \n Idea:\n concern:\n 1> how to avoid repeat or endless loop of person walking and box moving\n answer: S can repeat location when B is in di | brucezu | NORMAL | 2021-06-26T23:39:53.926018+00:00 | 2021-06-26T23:42:06.901788+00:00 | 190 | false | ```\n /*\n \n Idea:\n concern:\n 1> how to avoid repeat or endless loop of person walking and box moving\n answer: S can repeat location when B is in different location,\n but for a given fix B location, S should not repeat walking\n B should not repeat moving.\n need a v... | 1 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Don't step on the Box! | dont-step-on-the-box-by-liamdaburke-gc5u | ```\n def minPushBox(self, grid: List[List[str]]) -> int:\n for i, row in enumerate(grid):\n for j, col in enumerate(row):\n | liamdaburke | NORMAL | 2021-06-15T14:30:37.288868+00:00 | 2021-06-15T14:30:37.288935+00:00 | 357 | false | ```\n def minPushBox(self, grid: List[List[str]]) -> int:\n for i, row in enumerate(grid):\n for j, col in enumerate(row):\n if col == \'S\':\n si,sj = i,j\n elif col == \'B\':\n bi,bj = i,j\n elif col == \'T\':\n ... | 1 | 0 | ['Python'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Java - Dual BFS | java-dual-bfs-by-rv777-vyu8 | \n// We need to track the min number of steps that the box needs to be pushed to the target\n// We don\'t care how many steps the player takes\n// We will track | rv777 | NORMAL | 2021-06-10T04:48:11.051195+00:00 | 2021-08-12T17:00:07.510842+00:00 | 278 | false | ```\n// We need to track the min number of steps that the box needs to be pushed to the target\n// We don\'t care how many steps the player takes\n// We will track the state of the box and the player\n// For every box position we consider each possible next box position\n// - The usual checks, is the box position in... | 1 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | c# A* | c-a-by-cpp0x-o96j | Using custom Heap and A* algorithm from https://www.redblobgames.com/pathfinding/a-star/implementation.html#python-astar\n\n\npublic class Solution \n{\n\tpubli | cpp0x | NORMAL | 2021-01-12T10:15:43.525231+00:00 | 2021-01-12T10:51:19.633722+00:00 | 254 | false | Using custom Heap and A* algorithm from https://www.redblobgames.com/pathfinding/a-star/implementation.html#python-astar\n\n```\npublic class Solution \n{\n\tpublic int MinPushBox(char[][] grid)\n\t{\n\t\tPoint target = new Point();\n\t\tPoint startBox = new Point();\n\t\tPoint startPerson = new Point();\n\t\tfor (int ... | 1 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | C++ BFS - DFS solution [32ms] | c-bfs-dfs-solution-32ms-by-varkey98-26fm | \nvector<int> dx={1,0,-1,0};\nvector<int> dy={0,1,0,-1};\nint memo[20][20];\nbool dfs(int i1,int j1,int i2,int j2,int b1,int b2,vector<vector<char>>& grid)\n{\n | varkey98 | NORMAL | 2020-08-18T11:48:28.170029+00:00 | 2020-08-18T11:48:28.170061+00:00 | 487 | false | ```\nvector<int> dx={1,0,-1,0};\nvector<int> dy={0,1,0,-1};\nint memo[20][20];\nbool dfs(int i1,int j1,int i2,int j2,int b1,int b2,vector<vector<char>>& grid)\n{\n memset(memo,0,sizeof(memo)); \n return hasPath(i1,j1,i2,j2,b1,b2,grid);\n}\nbool hasPath(int i1,int j1,int i2,int j2,int b1,int b2,vector<vector<char... | 1 | 0 | ['Depth-First Search', 'Breadth-First Search', 'C'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Idiomatic Rust using BFS | idiomatic-rust-using-bfs-by-yeetcoder473-tnrq | Long but idiomatic solution in Rust.\n\n\nuse std::collections::{HashSet, VecDeque};\n\n#[derive(PartialEq, Eq, Hash, Debug, Clone, Copy)]\nenum Tile {\n Wal | yeetcoder4736 | NORMAL | 2020-07-23T23:41:25.516204+00:00 | 2020-07-23T23:41:25.516254+00:00 | 57 | false | Long but idiomatic solution in Rust.\n\n```\nuse std::collections::{HashSet, VecDeque};\n\n#[derive(PartialEq, Eq, Hash, Debug, Clone, Copy)]\nenum Tile {\n Wall,\n Empty,\n}\n\n#[derive(PartialEq, Eq, Hash, Debug, Clone, Copy)]\nstruct Position {\n i: usize,\n j: usize,\n}\n\nimpl Position {\n pub fn ne... | 1 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Need help for one test case | need-help-for-one-test-case-by-rralex-z205 | In my opinion, for the test case below, the answer should be 5 instead of 7\n\n\n{\n{\'#\',\'.\',\'.\',\'#\',\'#\',\'#\',\'#\',\'#\'},\n{\'#\',\'.\',\'.\',\'T\' | rralex | NORMAL | 2020-03-10T14:33:35.698559+00:00 | 2020-03-10T14:35:59.529143+00:00 | 120 | false | In my opinion, for the test case below, the answer should be 5 instead of 7\n\n```\n{\n{\'#\',\'.\',\'.\',\'#\',\'#\',\'#\',\'#\',\'#\'},\n{\'#\',\'.\',\'.\',\'T\',\'#\',\'.\',\'.\',\'#\'},\n{\'#\',\'.\',\'.\',\'.\',\'#\',\'B\',\'.\',\'#\'},\n{\'#\',\'.\',\'.\',\'.\',\'.\',\'.\',\'.\',\'#\'},\n{\'#\',\'.\',\'.\',\'.\',... | 1 | 0 | [] | 1 |
minimum-moves-to-move-a-box-to-their-target-location | Javascript A* search implementation | javascript-a-search-implementation-by-de-5m9l | 168 ms, 45.9MB\n\nAn ugly implementation, but since didn\'t see a javascript implementation of this yet decided to post mine up to see if it helps someone. The | dejeckt | NORMAL | 2020-02-03T08:17:04.956212+00:00 | 2020-02-03T08:17:04.956268+00:00 | 222 | false | 168 ms, 45.9MB\n\nAn ugly implementation, but since didn\'t see a javascript implementation of this yet decided to post mine up to see if it helps someone. The priorityqueue implementation was straight lifted from a stack overflow post. Basically a* search is bfs + heuristics + priorityqueue. Used the same heuristic th... | 1 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | C++ two BFS solution | c-two-bfs-solution-by-jake1900-9hkg | ```\nclass Solution {\npublic:\n \n vector dx = {0, 1, 0, -1};\n vector dy = {1, 0, -1, 0};\n pair B;\n pair P;\n pair T;\n \n struct no | jake1900 | NORMAL | 2020-01-29T11:54:31.285040+00:00 | 2020-01-29T11:54:31.285075+00:00 | 442 | false | ```\nclass Solution {\npublic:\n \n vector<int> dx = {0, 1, 0, -1};\n vector<int> dy = {1, 0, -1, 0};\n pair<int, int> B;\n pair<int, int> P;\n pair<int, int> T;\n \n struct node {\n int x;\n int y;\n int px;\n int py;\n node(int x, int y, int px, int py) : x(x... | 1 | 0 | ['Breadth-First Search', 'C'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Python Dijkstra solution | python-dijkstra-solution-by-merciless-gir8 | ```\nclass Solution:\n def minPushBox(self, m: List[List[str]]) -> int:\n de = ((1,0),(0,1),(-1,0),(0,-1))\n rl,cl = len(m),len(m[0])\n | merciless | NORMAL | 2019-12-06T21:45:27.694143+00:00 | 2019-12-06T21:45:27.694177+00:00 | 302 | false | ```\nclass Solution:\n def minPushBox(self, m: List[List[str]]) -> int:\n de = ((1,0),(0,1),(-1,0),(0,-1))\n rl,cl = len(m),len(m[0])\n memo, q = set(), []\n for i in range(rl):\n for j in range(cl):\n if m[i][j] == "T":\n tx,ty = i,j\n ... | 1 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Golang BFS Solution | golang-bfs-solution-by-shuoyan-b5dj | Inspired by : https://leetcode.com/problems/minimum-moves-to-move-a-box-to-their-target-location/discuss/431431/Java-straightforward-BFS-solution\n\ngolang\nfun | shuoyan | NORMAL | 2019-12-05T06:21:39.782382+00:00 | 2019-12-05T06:22:22.281353+00:00 | 108 | false | Inspired by : https://leetcode.com/problems/minimum-moves-to-move-a-box-to-their-target-location/discuss/431431/Java-straightforward-BFS-solution\n\n```golang\nfunc minPushBox(grid [][]byte) int {\n\tmv := [5]int{0, 1, 0, -1, 0}\n\tres := math.MaxInt32\n\tm := len(grid)\n\tn := len(grid[0])\n\tqueue := make([]int, 0, m... | 1 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | python3, 32ms, 100%, tarjan+A* | python3-32ms-100-tarjana-by-typingmonkey-toyf | python []\nclass Solution:\n def minPushBox(self, grid: List[List[str]]) -> int:\n m, n, g = len(grid), len(grid[0]), collections.defaultdict(list)\n | typingmonkeyli | NORMAL | 2019-12-02T17:33:19.002426+00:00 | 2019-12-12T15:24:35.870387+00:00 | 254 | false | ```python []\nclass Solution:\n def minPushBox(self, grid: List[List[str]]) -> int:\n m, n, g = len(grid), len(grid[0]), collections.defaultdict(list)\n for i in range(m):\n for j in range(n):\n g[grid[i][j]] += [complex(i, j)]\n def f(b, s): \n nonlocal time... | 1 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Java | java-by-jzyz-v34k | \nimport java.util.*;\n\nclass Solution {\n int m, n;\n char[][] grid;\n private static final int[][] DIRECTIONS = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};\ | jzyz | NORMAL | 2019-11-24T01:43:52.662710+00:00 | 2019-11-24T01:43:52.662745+00:00 | 245 | false | ```\nimport java.util.*;\n\nclass Solution {\n int m, n;\n char[][] grid;\n private static final int[][] DIRECTIONS = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};\n\n public int minPushBox(char[][] grid) {\n Queue<int[]> q1 = new ArrayDeque<>();\n int[] man = null, box = null, destination = null;\n ... | 1 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | BFS + DFS Simple C++ solution | Easy to understand with Explanation | bfs-dfs-simple-c-solution-easy-to-unders-i0zu | Intuition:\n\n1. For a moment lets forget about the player and reduce our problem to what is the minimum push that is required to place the box to it\'s target? | himsingh11 | NORMAL | 2019-11-21T18:31:17.945247+00:00 | 2019-12-02T03:06:42.955283+00:00 | 646 | false | Intuition:\n\n1. For a moment lets forget about the player and reduce our problem to `what is the minimum push that is required to place the box to it\'s target?` , the obvious answer come to our mind is to use BFS to get this answer.\n2. Now we can assume what if someone has to push the box to place it to target and w... | 1 | 0 | ['Depth-First Search', 'Breadth-First Search', 'C++'] | 1 |
minimum-moves-to-move-a-box-to-their-target-location | Python3 nested BFS (95.82%) | python3-nested-bfs-9582-by-ye15-q7aj | Outer BFS - move box to next place \nInner BFS - check if player can be placed to move box to next place \n\n\nfrom itertools import product\n\nclass Solution:\ | ye15 | NORMAL | 2019-11-20T06:12:49.658819+00:00 | 2019-11-20T06:12:49.658851+00:00 | 164 | false | Outer BFS - move box to next place \nInner BFS - check if player can be placed to move box to next place \n\n```\nfrom itertools import product\n\nclass Solution:\n def minPushBox(self, grid: List[List[str]]) -> int:\n #constants\n m, n = len(grid), len(grid[0]) #dimensions\n neighbors = ((-1,0)... | 1 | 0 | ['Python3'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | The reason of adding person location in seen or visited set. | the-reason-of-adding-person-location-in-74k1u | If BFS is used, if we do not add the location of the person to the seen set, we will get an error for the following test case. It is supposed to get 8, however, | liketheflower | NORMAL | 2019-11-19T04:36:29.212027+00:00 | 2019-11-19T04:37:06.750465+00:00 | 114 | false | If BFS is used, if we do not add the location of the person to the seen set, we will get an error for the following test case. It is supposed to get 8, however, without the person add in the seen set, we will get -1.\nThe @ location is critical. When the box is pushed to the location of "@", it has to be moved to the l... | 1 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Summary of BFS+BFS, BFS+DFS, BFS+UnionFind and other possible ways. | summary-of-bfsbfs-bfsdfs-bfsunionfind-an-qxi1 | The solution to this problem can be: BFS + BFS or BFS + DFS or BFS + Union Find\nIn the code\nbi, bj, pi, pj mean the box location and person location. ti, tj m | liketheflower | NORMAL | 2019-11-19T04:14:35.373565+00:00 | 2019-11-19T04:39:59.760735+00:00 | 237 | false | The solution to this problem can be: BFS + BFS or BFS + DFS or BFS + Union Find\nIn the code\nbi, bj, pi, pj mean the box location and person location. ti, tj mean the target location of the person in order to push the box.\nSolution 1(BFS + BFS, runtime 160ms)\n```python\nclass Solution:\n def minPushBox(self, grid... | 1 | 0 | [] | 1 |
minimum-moves-to-move-a-box-to-their-target-location | Python [for newbie] BFS, borrowed from @davyjing | python-for-newbie-bfs-borrowed-from-davy-emxf | I cleaned a bit the excellent code of @davyjing for new comers. \n\nclass Solution:\n def minPushBox(self, grid: List[List[str]]) -> int:\n m, n = len | bos | NORMAL | 2019-11-17T19:37:50.576501+00:00 | 2019-11-18T17:39:58.237015+00:00 | 233 | false | I cleaned a bit the excellent code of @davyjing for new comers. \n```\nclass Solution:\n def minPushBox(self, grid: List[List[str]]) -> int:\n m, n = len(grid), len(grid[0])\n for i in range(m):\n for j in range(n):\n if grid[i][j] == \'B\': box = (i, j)\n if gr... | 1 | 0 | [] | 1 |
minimum-moves-to-move-a-box-to-their-target-location | BFS with (box pos+ direction) as the state | bfs-with-box-pos-direction-as-the-state-y21jl | \n\nclass Solution {\n int m=0,n=0;\n public int minPushBox(char[][] grid) {\n m=grid.length;\n n=grid[0].length;\n int sx=0,sy=0,bx= | leon123 | NORMAL | 2019-11-17T06:09:49.925487+00:00 | 2019-11-17T06:09:49.925535+00:00 | 151 | false | ```\n\nclass Solution {\n int m=0,n=0;\n public int minPushBox(char[][] grid) {\n m=grid.length;\n n=grid[0].length;\n int sx=0,sy=0,bx=0,by=0,tx=0,ty=0;\n for(int i=0;i<m;i++) for(int j=0;j<n;j++){\n if(grid[i][j]==\'S\'){sx=i;sy=j;grid[i][j]=\'.\';}\n if(grid[i]... | 1 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Python3 2-level BFS, a few notes | python3-2-level-bfs-a-few-notes-by-hello-nql0 | A few key points that distinguishes this problem from your typical BFS:\n\n1. To push the box to a specific direction, player has to be at the opposite directio | helloterran | NORMAL | 2019-11-17T05:09:59.178280+00:00 | 2019-11-17T05:10:19.453873+00:00 | 231 | false | A few key points that distinguishes this problem from your typical BFS:\n\n1. To push the box to a specific direction, player has to be at the opposite direction. So there needs be empty space on both sides\n\n2. Player has to be able to find a path from previous position to the needed position described in point 1 abo... | 1 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | one time bfs + priority_queue c++ (explaination included) | one-time-bfs-priority_queue-c-explainati-6tc9 | when we mark as visit we need two coords, box and keeper.\nbecause they all <= 20, so I just use 100 , and easy for debug,\nmy algorith first work on keeper min | 0xffffffff | NORMAL | 2019-11-17T04:28:59.858902+00:00 | 2019-11-17T04:38:07.925709+00:00 | 327 | false | when we mark as visit we need two coords, box and keeper.\nbecause they all <= 20, so I just use 100 , and easy for debug,\nmy algorith first work on keeper minimized moves, but the mini push is asked so have to use pq to pop min pushes.\n\n```\nclass Solution {\npublic:\n int minPushBox(vector<vector<char>>& grid) ... | 1 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | 2-stage DFS solution using java | 2-stage-dfs-solution-using-java-by-hunte-cezf | I used minReach array to record minimal reach steps from 4 directions, then using dfs to walk step by step, finally return minReach of target position.\n\nclass | huntersjm | NORMAL | 2019-11-17T04:20:22.798494+00:00 | 2019-11-17T04:20:22.798548+00:00 | 464 | false | I used minReach array to record minimal reach steps from 4 directions, then using dfs to walk step by step, finally return minReach of target position.\n```\nclass Solution {\n public int minPushBox(char[][] grid) {\n int[][][] minReach = new int[grid.length][grid[0].length][4];\n for (int i = 0; i < m... | 1 | 0 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Python - Very Upset. Finish 20 seconds after the contest end! | python-very-upset-finish-20-seconds-afte-ozgs | \nclass Solution:\n def minPushBox(self, grid: List[List[str]]) -> int:\n m, n = len(grid), len(grid[0])\n for i in range(m):\n for | llcourage123 | NORMAL | 2019-11-17T04:08:05.921839+00:00 | 2019-11-17T04:08:24.553104+00:00 | 262 | false | ```\nclass Solution:\n def minPushBox(self, grid: List[List[str]]) -> int:\n m, n = len(grid), len(grid[0])\n for i in range(m):\n for j in range(n):\n if grid[i][j] == "S":\n people = [i, j]\n if grid[i][j] == "T":\n end = ... | 1 | 1 | [] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | ✅✅✅Easiest Solution || Beats 76.69% || BFS Solution for LeetCode#1263✅✅✅✅ | easiest-solution-beats-7669-bfs-solution-kd2y | IntuitionThe problem requires pushing a box ('B') to a target ('T') while controlling a player ('S') in a grid with obstacles ('#'). The challenge is that the p | subhu04012003 | NORMAL | 2025-02-19T17:20:25.135698+00:00 | 2025-02-19T17:20:25.135698+00:00 | 5 | false | 
# Intuition
The problem requires pushing a box ('B') to a target ('T') while controlling a player ('S') in a grid with obstacles ('#'). The challenge is that the player must... | 0 | 0 | ['Array', 'Breadth-First Search', 'Heap (Priority Queue)', 'Matrix', 'C++'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Python Hard | python-hard-by-lucasschnee-2ush | null | lucasschnee | NORMAL | 2025-01-24T15:59:01.886349+00:00 | 2025-01-24T15:59:01.886349+00:00 | 8 | false | ```python3 []
class Solution:
def minPushBox(self, grid: List[List[str]]) -> int:
'''
m and n are very small
m * n * m * n is 20 ** 4 = 160000
so thats all we have to do
'''
directions = [(0, 1), (1, 0), (-1, 0), (0, -1)]
M, N = len(grid), len(grid[0... | 0 | 0 | ['Python3'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | 1263. Minimum Moves to Move a Box to Their Target Location | 1263-minimum-moves-to-move-a-box-to-thei-5l86 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | G8xd0QPqTy | NORMAL | 2025-01-04T04:33:45.005281+00:00 | 2025-01-04T04:33:45.005281+00:00 | 10 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['Java'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | My java 8ms solution 87% faster | my-java-8ms-solution-87-faster-by-raghav-6luz | 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 | raghavrathore7415 | NORMAL | 2024-10-20T13:55:11.361188+00:00 | 2024-10-20T13:57:35.206919+00:00 | 7 | 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)$$ --... | 0 | 0 | ['Java'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Python3 | Modified BFS and Heap | python3-modified-bfs-and-heap-by-tigprog-99rv | Complexity\n- Time complexity: O(m^2 \cdot n^2 \cdot \log(m^2 \cdot n^2))\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(m^2 \cdot n^2)\n | tigprog | NORMAL | 2024-10-07T16:45:33.308088+00:00 | 2024-10-07T16:46:06.487942+00:00 | 7 | false | # Complexity\n- Time complexity: $$O(m^2 \\cdot n^2 \\cdot \\log(m^2 \\cdot n^2))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(m^2 \\cdot n^2)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nimport heapq\n\nclass Solution:\n def minPushBox(se... | 0 | 0 | ['Breadth-First Search', 'Heap (Priority Queue)', 'Matrix', 'Python3'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | 1263. Minimum Moves to Move a Box to Their Target Location.cpp | 1263-minimum-moves-to-move-a-box-to-thei-owkf | Code\n\nclass Solution {\nprivate:\n int m, n;\n vector<pair<int, int>> dir;\n struct Hash {\n size_t operator()(const vector<int> &v) const {\n | 202021ganesh | NORMAL | 2024-09-20T09:46:11.727143+00:00 | 2024-09-20T09:46:11.727171+00:00 | 0 | false | **Code**\n```\nclass Solution {\nprivate:\n int m, n;\n vector<pair<int, int>> dir;\n struct Hash {\n size_t operator()(const vector<int> &v) const {\n return v[0] * 20 + v[1] + v[2] * 20 + v[3];\n }\n };\n unordered_set<vector<int>, Hash> visited;\n struct Hash2 {\n si... | 0 | 0 | ['C'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | C++ - Double BFS | c-double-bfs-by-a4yan1-ksuc | Code\n\nclass Solution {\npublic:\n static constexpr int drow[4] = {-1,0,1,0};\n static constexpr int dcol[4] = {0,1,0,-1};\n bool isPossible(int box_r | a4yan1 | NORMAL | 2024-08-18T04:04:18.198933+00:00 | 2024-08-18T04:04:18.198965+00:00 | 25 | false | # Code\n```\nclass Solution {\npublic:\n static constexpr int drow[4] = {-1,0,1,0};\n static constexpr int dcol[4] = {0,1,0,-1};\n bool isPossible(int box_row,int box_col,int dest_row,int dest_col,int row,int col,vector<vector<char>> &grid){\n int n = grid.size(); int m = grid[0].size();\n if(des... | 0 | 0 | ['Breadth-First Search', 'Matrix', 'C++'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | C++ Solution || BFS || Easy to Understand || Fully Explanation | c-solution-bfs-easy-to-understand-fully-9dyq8 | Approach\n\nThis problem has two sub-problems:\n - Find the path from box to target, using BFS\n - Find the path from player to the position which is posi | dnanper | NORMAL | 2024-08-02T11:25:10.488476+00:00 | 2024-08-02T11:25:10.488498+00:00 | 13 | false | # Approach\n\nThis problem has two sub-problems:\n - Find the path from box to target, using BFS\n - Find the path from player to the position which is posible to push the box, using BFS\n \nBFS state is the position of the box and the player\n\nAfter push the box, the position of player is in the box\'s previ... | 0 | 0 | ['C++'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | A* short C++ version | a-short-c-version-by-rsysz-pvhi | https://leetcode.com/problems/minimum-moves-to-move-a-box-to-their-target-location/solutions/431061/a-star-search/\n\n# Code\n\nstruct Node {\n int playerX, | rsysz | NORMAL | 2024-07-27T07:55:09.221778+00:00 | 2024-07-27T07:55:09.221800+00:00 | 0 | false | https://leetcode.com/problems/minimum-moves-to-move-a-box-to-their-target-location/solutions/431061/a-star-search/\n\n# Code\n```\nstruct Node {\n int playerX, playerY;\n int boxX, boxY;\n int g, h, f; // f = g + h\n\n bool operator < (const Node& n) const {\n return n.f < f;\n }\n};\n\nclass Solu... | 0 | 0 | ['C++'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Standard BFS with Twist - Expand on Pushes, not Steps | standard-bfs-with-twist-expand-on-pushes-kwlo | Intuition\n Describe your first thoughts on how to solve this problem. \nA very conventional BFS algorithm with a small twist. Instead of always adding to the e | matt_scott | NORMAL | 2024-07-26T03:36:12.069605+00:00 | 2024-07-26T03:36:12.069639+00:00 | 5 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nA very conventional BFS algorithm with a small twist. Instead of always adding to the end of the queue, we should prioritise nodes (greedily) with less steps and expand them first\n\n# Approach\n<!-- Describe your approach to solving the ... | 0 | 0 | ['Python3'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Python 0-1 BFS, Straightforward | python-0-1-bfs-straightforward-by-brando-edyl | Intuition / Approach\nWe can view this problem is a state-space single source shortest path (SSSP) problem.\n\nWe formulate each state as a tuple $(r, c, x, y)$ | BrandonTang89 | NORMAL | 2024-07-21T07:43:18.764554+00:00 | 2024-07-21T07:43:50.994243+00:00 | 5 | false | # Intuition / Approach\nWe can view this problem is a state-space single source shortest path (SSSP) problem.\n\nWe formulate each state as a tuple $(r, c, x, y)$ where $(r,c)$ is the position of the player and $(x, y)$ is the position of the box.\n- The initial state is $(r, c, x, y)$ where `grid[r][c] = "S"` and `gri... | 0 | 0 | ['Python3'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Both Dijkstra and A star. Easy for comparison | both-dijkstra-and-a-star-easy-for-compar-tdk0 | \n# Dijkstra: \nAlgorithm for shortest path from origin. Only consider the distance from origin.\n\nIn essence: dijkstra is advanced BFS(breadth-first search). | mythsky | NORMAL | 2024-05-27T05:52:28.443570+00:00 | 2024-10-22T05:34:09.048715+00:00 | 17 | false | \n# Dijkstra: \nAlgorithm for shortest path from origin. Only consider the distance from origin.\n\n**In essence**: dijkstra is advanced BFS(breadth-first search). The only difference is Dijkstra search through the shorter path first. The idea is the future step of shorter path has potential to replace the current long... | 0 | 0 | ['Python3'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Dijkstra solution | dijkstra-solution-by-mythsky-ghyy | 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 | mythsky | NORMAL | 2024-05-27T04:27:04.825623+00:00 | 2024-05-27T04:27:04.825641+00:00 | 6 | 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)$$ --... | 0 | 0 | ['Python3'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Djikstra | djikstra-by-muzakkiy-ad4u | Intuition\nThe Box Movement will follow the person movement, if the person movement to the left, box should move also to the left. this means, if our next move | muzakkiy | NORMAL | 2024-05-10T14:04:27.808015+00:00 | 2024-05-10T14:04:27.808062+00:00 | 6 | false | # Intuition\nThe Box Movement will follow the person movement, if the person movement to the left, box should move also to the left. this means, if our next move is a current box state, we need to push the box the same direction with us. for example, if we move 1 point to left, the box also need to move 1 point. but sh... | 0 | 0 | ['Go'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Djikstra | djikstra-by-muzakkiy-aalb | Intuition\nThe Box Movement will follow the person movement, if the person movement to the left, box should move also to the left. this means, if our next move | muzakkiy | NORMAL | 2024-05-10T14:04:21.639125+00:00 | 2024-05-10T14:04:21.639159+00:00 | 1 | false | # Intuition\nThe Box Movement will follow the person movement, if the person movement to the left, box should move also to the left. this means, if our next move is a current box state, we need to push the box the same direction with us. for example, if we move 1 point to left, the box also need to move 1 point. but sh... | 0 | 0 | ['Go'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Bidirectional Search+ A* Search (70 ms Beats 100%) | bidirectional-search-a-search-70-ms-beat-pbb9 | \nclass Solution:\n def minPushBox(self, grid: List[List[str]]) -> int:\n m = len(grid)\n n = len(grid[0])\n directions = [(0,-1), (0,1) | laxelee1 | NORMAL | 2024-04-19T16:27:21.762123+00:00 | 2024-04-19T16:27:21.762158+00:00 | 4 | false | ```\nclass Solution:\n def minPushBox(self, grid: List[List[str]]) -> int:\n m = len(grid)\n n = len(grid[0])\n directions = [(0,-1), (0,1), (-1,0), (1,0)] # left, right, up, down\n\n found = 0\n for i in range(m):\n for j in range(n):\n if grid[i][j] in (... | 0 | 0 | ['Python3'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | BFS with composite encoded key for visited | bfs-with-composite-encoded-key-for-visit-3n9d | Intuition\nBecause this is a grid, edge weights are equal,\nso we can use BFS instead of UCS or A.\n\nA BFS search can be done from the box to the target,\nbut | _nichole_ | NORMAL | 2024-04-18T23:42:34.173873+00:00 | 2024-04-18T23:42:34.173918+00:00 | 5 | false | # Intuition\nBecause this is a grid, edge weights are equal,\nso we can use BFS instead of UCS or A*.\n\nA BFS search can be done from the box to the target,\nbut each move of the box must have a free space\non the opposite side of move,\nand that free space must be reachable by S at its current position.\n\n\n# Approa... | 0 | 0 | ['Java'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Ugly solution | ugly-solution-by-yoongyeom-l2g3 | Code\n\nclass Solution:\n def minPushBox(self, grid: List[List[str]]) -> int:\n def canvisit(r1, c1, r2, c2, r3, c3):\n if (r1, c1) == (r2, | YoonGyeom | NORMAL | 2024-04-05T13:32:18.407783+00:00 | 2024-04-05T13:32:18.407817+00:00 | 2 | false | # Code\n```\nclass Solution:\n def minPushBox(self, grid: List[List[str]]) -> int:\n def canvisit(r1, c1, r2, c2, r3, c3):\n if (r1, c1) == (r2, c2): return True\n grid[r3][c3] = \'R\'\n q = [(r1, c1)]\n seen = set([(r1, c1)])\n while q:\n ... | 0 | 0 | ['Python3'] | 0 |
minimum-moves-to-move-a-box-to-their-target-location | Beats 100% users | beats-100-users-by-aim_high_212-bvdl | 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 | Aim_High_212 | NORMAL | 2024-03-11T15:00:04.920886+00:00 | 2024-03-11T15:00:04.920907+00:00 | 7 | 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)$$ --... | 0 | 0 | ['Python', 'Python3'] | 0 |
minimum-deletions-to-make-array-beautiful | ✅ Best and Most Easy Explanantion || 3 line of code | best-and-most-easy-explanantion-3-line-o-wa13 | \uD83D\uDC68\u200D\uD83D\uDCBB Friend\'s if you find this solution helpful \uD83D\uDE0A, PLEASE do UPVOTE. By doing that motivates me to create a better post li | intellisense | NORMAL | 2022-03-27T05:11:07.462749+00:00 | 2022-03-27T05:27:02.504074+00:00 | 6,377 | false | \uD83D\uDC68\u200D\uD83D\uDCBB Friend\'s if you find this solution helpful \uD83D\uDE0A, PLEASE do UPVOTE. By doing that motivates me to create a better post like this \u270D\uFE0F\n____________________________________________________________________________________________________________\n____________________________... | 168 | 2 | ['C'] | 11 |
minimum-deletions-to-make-array-beautiful | [Java/C++/Python] O(1) Greedy Solution with Explanation | javacpython-o1-greedy-solution-with-expl-qouv | Solution 1\nGreedily add all element to a result array.\n\nAnyway, greedy solution is not obvious to be right.\nTo handle every continuous elements pair, we act | lee215 | NORMAL | 2022-03-27T04:04:57.613754+00:00 | 2022-03-27T04:40:17.221625+00:00 | 7,423 | false | # **Solution 1**\nGreedily add all element to a result array.\n\nAnyway, greedy solution is not obvious to be right.\nTo handle every continuous elements pair, we actually only care if the number of deleted numbers is even or single.\n\nWe never need to delete a number when not necessary to optimize the deleting in fut... | 61 | 4 | ['C', 'Python', 'Java'] | 15 |
minimum-deletions-to-make-array-beautiful | ✅ C++ | Easy | c-easy-by-chandanagrawal23-fmfy | \nclass Solution\n{\n public:\n int minDeletion(vector<int> &nums)\n {\n int shift = 0;\n for (int i = 0; i < nums.size() | chandanagrawal23 | NORMAL | 2022-03-27T04:02:12.309238+00:00 | 2022-03-27T04:41:04.548760+00:00 | 2,577 | false | ```\nclass Solution\n{\n public:\n int minDeletion(vector<int> &nums)\n {\n int shift = 0;\n for (int i = 0; i < nums.size() - 1; i++)\n {\n if ((i + shift) % 2 == 0)\n {\n if (nums[i] == nums[i + 1])\n ... | 37 | 2 | [] | 5 |
minimum-deletions-to-make-array-beautiful | Java/C++ | O(N) time O(1) space | javac-on-time-o1-space-by-surajthapliyal-v2im | JAVA\n\nclass Solution {\n\n public int minDeletion(int[] nums) {\n boolean even = true;\n int size = 0, c = 0;\n for (int i = 0; i < nu | surajthapliyal | NORMAL | 2022-03-27T04:02:16.596387+00:00 | 2022-03-28T06:41:21.403842+00:00 | 2,898 | false | **JAVA**\n```\nclass Solution {\n\n public int minDeletion(int[] nums) {\n boolean even = true;\n int size = 0, c = 0;\n for (int i = 0; i < nums.length; i++) {\n\t\t\t//current index is even and i+1 is same \n while (i + 1 < nums.length && even && nums[i] == nums[i + 1]) {\n ... | 30 | 0 | [] | 10 |
minimum-deletions-to-make-array-beautiful | [JAVA]Simple Detailed Solution with O(N) time O(1) space!! | javasimple-detailed-solution-with-on-tim-o46y | The idea is simple go through the array along with checking the conditions!!\n\n\n\n int counter = 0;\n for (int i = 0; i < nums.length - 1; i += | sadriddin17 | NORMAL | 2022-03-27T04:03:19.572463+00:00 | 2022-03-27T05:04:00.417313+00:00 | 1,179 | false | The idea is simple go through the array along with checking the conditions!!\n\n\n```\n int counter = 0;\n for (int i = 0; i < nums.length - 1; i += 2) { // the second condition given\n ... | 25 | 0 | ['Java'] | 3 |
minimum-deletions-to-make-array-beautiful | Two Pointers | two-pointers-by-votrubac-w5me | This problem may look harder than it is. We just need to realize that we always have to delete if two consecutive elements (after the shift) are equal.\n\nWe ca | votrubac | NORMAL | 2022-03-27T04:01:43.323112+00:00 | 2022-03-27T04:10:29.534674+00:00 | 2,076 | false | This problem may look harder than it is. We just need to realize that we always have to delete if two consecutive elements (after the shift) are equal.\n\nWe can use the two-pointer approach to track the shift (`j`).\n\n**C++**\n```cpp\nint minDeletion(vector<int>& nums) {\n int j = 0, sz = nums.size();\n for(int... | 22 | 1 | ['C'] | 4 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.