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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
path-sum | Python || Dfs || binary tree leaves find all paths | python-dfs-binary-tree-leaves-find-all-p-holi | It is intuitive to find all the possible paths from roots to leaves and sum them and check with the target sum.\n\nclass Solution:\n def hasPathSum(self, roo | ana_2kacer | NORMAL | 2022-07-03T07:02:21.614449+00:00 | 2022-07-03T07:02:21.614493+00:00 | 432 | false | It is intuitive to find all the possible paths from roots to leaves and sum them and check with the target sum.\n```\nclass Solution:\n def hasPathSum(self, root: Optional[TreeNode], targetSum: int) -> bool:\n res = []\n if not root:\n return False\n def dfs(r,path):\n if n... | 8 | 0 | ['Depth-First Search', 'Recursion', 'Python', 'Python3'] | 1 |
path-sum | Python/JS/Go/C++ O(n) DFS [w/ Hint ] 有中文解題文章 | pythonjsgoc-on-dfs-w-hint-you-zhong-wen-xrckw | \u6709\u4E2D\u6587\u89E3\u984C\u6587\u7AE0\n\nPython O(n) sol by DFS\n\n---\nHint:\n\nThink of DFS algorithm framework\n\nOne node is the so-called leaf node, i | brianchiang_tw | NORMAL | 2020-03-01T07:40:41.063832+00:00 | 2024-01-29T12:35:38.339368+00:00 | 1,165 | false | [\u6709\u4E2D\u6587\u89E3\u984C\u6587\u7AE0](https://vocus.cc/article/65b77662fd8978000192c491)\n\nPython O(n) sol by DFS\n\n---\n**Hint**:\n\nThink of **DFS** algorithm framework\n\nOne node is the so-called **leaf node**, if and only if,\nit is **not an empty node** and it **doesn\'t have** both *left child* and *rig... | 8 | 1 | ['Stack', 'Depth-First Search', 'Recursion', 'C', 'Python', 'C++', 'Go', 'JavaScript'] | 0 |
path-sum | Go 4ms | go-4ms-by-dynasty919-fq7m | \nfunc hasPathSum(root *TreeNode, sum int) bool {\n if root == nil {\n return false\n }\n if root.Left == nil && root.Right == nil {\n re | dynasty919 | NORMAL | 2020-02-24T13:52:03.754115+00:00 | 2020-02-24T13:52:03.754158+00:00 | 367 | false | ```\nfunc hasPathSum(root *TreeNode, sum int) bool {\n if root == nil {\n return false\n }\n if root.Left == nil && root.Right == nil {\n return sum == root.Val\n }\n return hasPathSum(root.Left, sum - root.Val) || hasPathSum(root.Right, sum - root.Val)\n}\n``` | 8 | 0 | [] | 1 |
path-sum | Simple Python solution, recursive and iterative (using DFS) | simple-python-solution-recursive-and-ite-vejc | Recursive\n\n\nclass Solution:\n def hasPathSum(self, root: TreeNode, sum: int) -> bool:\n if not root:\n return False\n \n s | johanndiedrick | NORMAL | 2019-10-21T20:25:24.412698+00:00 | 2019-10-21T20:25:24.412749+00:00 | 960 | false | **Recursive**\n\n```\nclass Solution:\n def hasPathSum(self, root: TreeNode, sum: int) -> bool:\n if not root:\n return False\n \n sum = sum - root.val\n \n if not root.left and not root.right: #leaf node\n return sum == 0\n else:\n return se... | 8 | 0 | ['Tree', 'Depth-First Search', 'Recursion', 'Iterator', 'Python'] | 2 |
path-sum | JavaScript-Easy top-bottom approach. | javascript-easy-top-bottom-approach-by-l-7je6 | \nvar hasPathSum = function(root, sum) {\n if (!root) return false;\n let queue = [root];\n while (queue.length > 0) {\n let cur = queue.shift() | lazy_tym | NORMAL | 2019-09-23T15:33:48.885097+00:00 | 2019-09-23T15:33:48.885130+00:00 | 1,124 | false | ```\nvar hasPathSum = function(root, sum) {\n if (!root) return false;\n let queue = [root];\n while (queue.length > 0) {\n let cur = queue.shift();\n if (!cur.left && !cur.right && cur.val == sum) {\n return true;\n }\n if (cur.left) {\n cur.left.val += cur.va... | 8 | 0 | ['JavaScript'] | 3 |
path-sum | Just another java solution, recursive. simple but can be simpler. | just-another-java-solution-recursive-sim-rbz5 | /**\n * Definition for binary tree\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * T | salg | NORMAL | 2014-11-26T04:12:03+00:00 | 2014-11-26T04:12:03+00:00 | 1,259 | false | /**\n * Definition for binary tree\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\n public class Solution {\n public boolean hasPathSum(TreeNode root, int sum) {\n //star... | 8 | 0 | [] | 2 |
path-sum | 12ms C++ solution | 12ms-c-solution-by-pjlloyd100-dhuc | class Solution {\n public:\n bool hasPathSum(TreeNode* root, int sum) {\n if(root == NULL) return false;\n sum -= root->val;\n | pjlloyd100 | NORMAL | 2015-07-06T15:54:23+00:00 | 2015-07-06T15:54:23+00:00 | 1,727 | false | class Solution {\n public:\n bool hasPathSum(TreeNode* root, int sum) {\n if(root == NULL) return false;\n sum -= root->val;\n return sum == 0 && root->left == NULL && root->right == NULL ? true : hasPathSum(root->left, sum) | hasPathSum(root->right, sum);\n }\n ... | 8 | 0 | [] | 2 |
path-sum | My Java solution using Recursive | my-java-solution-using-recursive-by-viol-5pm2 | \n public boolean hasPathSum(TreeNode root, int sum) {\n if (root == null) {\n return false;\n } else {\n if (root.left = | violinn | NORMAL | 2015-10-24T08:56:43+00:00 | 2015-10-24T08:56:43+00:00 | 1,025 | false | \n public boolean hasPathSum(TreeNode root, int sum) {\n if (root == null) {\n return false;\n } else {\n if (root.left == null && root.right == null) {\n return sum == root.val;\n } else {\n int subSum = sum - root.val;\n ... | 8 | 0 | [] | 0 |
path-sum | Simple c++ solution | simple-c-solution-by-xjq-nqiz | class Solution {\n public:\n bool hasPathSum(TreeNode* root, int sum) {\n if(root == NULL){\n return false;\n }\n | xjq | NORMAL | 2016-04-28T03:45:23+00:00 | 2016-04-28T03:45:23+00:00 | 1,404 | false | class Solution {\n public:\n bool hasPathSum(TreeNode* root, int sum) {\n if(root == NULL){\n return false;\n }\n int newsum = sum - root->val;\n if(root->left == NULL && root->right == NULL){\n return newsum == 0;\n }\n ... | 8 | 0 | ['C++'] | 0 |
path-sum | Path Sum [C++] | path-sum-c-by-moveeeax-e510 | IntuitionThe problem requires determining if there is a path from the root to a leaf node where the sum of the node values equals a target sum. This can be visu | moveeeax | NORMAL | 2025-01-28T13:11:16.178935+00:00 | 2025-01-28T13:11:16.178935+00:00 | 948 | false | # Intuition
The problem requires determining if there is a path from the root to a leaf node where the sum of the node values equals a target sum. This can be visualized as a decision tree, where at each node we decide to explore either the left or right subtree. If a path exists that satisfies the condition, we return... | 7 | 0 | ['C++'] | 0 |
path-sum | ✅26ms | 99.64% | Easy Solution | Recursive Solution | 3 lines of code | 26ms-9964-easy-solution-recursive-soluti-q82b | Intuition\nThe problem asks us to determine if there is a root-to-leaf path in a binary tree that sums up to a given target sum. My first thought was to recursi | CodeWithCharan | NORMAL | 2024-08-29T12:51:48.635687+00:00 | 2024-08-29T12:51:48.635715+00:00 | 867 | false | # Intuition\nThe problem asks us to determine if there is a root-to-leaf path in a binary tree that sums up to a given target sum. My first thought was to recursively explore each path from the root to the leaf nodes, keeping track of the remaining sum as we traverse down the tree. If we reach a leaf node and the remai... | 7 | 0 | ['Tree', 'Depth-First Search', 'Recursion', 'Binary Tree', 'Python3'] | 2 |
path-sum | easy go solution | easy-go-solution-by-debasmitasaha23-p3f2 | 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 | debasmitasaha23 | NORMAL | 2022-12-08T07:44:59.148481+00:00 | 2022-12-08T07:44:59.148518+00:00 | 571 | 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)$$ --... | 7 | 0 | ['Go'] | 0 |
path-sum | O(n)time/BEATS 99.97% MEMORY/SPEED 0ms MAY 2022 | ontimebeats-9997-memoryspeed-0ms-may-202-8988 | \n\n\n(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful, please upvote this post.)\nTake care broth | darian-catalin-cucer | NORMAL | 2022-05-15T04:22:47.667078+00:00 | 2022-05-15T04:22:47.667104+00:00 | 1,234 | false | ```\n```\n\n(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful, ***please upvote*** this post.)\n***Take care brother, peace, love!***\n\n```\n```\n\n```\n```\n\n```\n```\n\nThe best result for the code below is ***0ms / 38.2MB*** (beats 92.04% / 24.00%).\n* *... | 7 | 0 | ['Recursion', 'Swift', 'C', 'PHP', 'Python', 'Java', 'Kotlin', 'JavaScript'] | 2 |
path-sum | [JavaScript] Easy to understand - DFS | javascript-easy-to-understand-dfs-by-pop-kx4r | Since we need to sum the values from root to leaf, it\'s straightforward to think about DFS. So, the process could be:\n1. Traverse the tree via DFS\n2. Check w | poppinlp | NORMAL | 2021-11-09T02:11:42.483945+00:00 | 2021-11-09T02:11:42.483979+00:00 | 573 | false | Since we need to sum the values from root to leaf, it\'s straightforward to think about DFS. So, the process could be:\n1. Traverse the tree via DFS\n2. Check whether current node is leaf\n\t- check the target value\n\t- continue recursion\n\nHere\'s the code:\n\n```js\nconst hasPathSum = (node, target) => {\n if (!no... | 7 | 0 | ['JavaScript'] | 0 |
path-sum | Two Approaches, DFS, Very simple, C++ | two-approaches-dfs-very-simple-c-by-akas-tir8 | \nImplementation\n\n1st Approach using helper(findPath) method\nTime Complexity = O(N), Space Complexity = O(H) where H is the height of the Binary Tree\n\n\ncl | akashsahuji | NORMAL | 2021-10-12T14:07:42.544506+00:00 | 2021-10-25T01:43:47.767677+00:00 | 507 | false | \nImplementation\n\n**1st Approach using helper(findPath) method\nTime Complexity = O(N), Space Complexity = O(H) where H is the height of the Binary Tree**\n\n```\nclass Solution {\npublic:\n bool findPath(TreeNode* root, int targetSum, int sum){\n if(root == NULL) return false;\n sum += root->val;\n ... | 7 | 0 | ['Depth-First Search', 'Recursion', 'C', 'Binary Tree'] | 4 |
path-sum | JAVA [DFS] : Runtime: 0 ms, faster than 100.00% & Memory Usage: 39.2 MB, less than 73.39% | java-dfs-runtime-0-ms-faster-than-10000-d2fad | \n// Runtime: 0 ms, faster than 100.00% of Java online submissions for Path Sum.\n// Memory Usage: 39.2 MB, less than 73.39% of Java online submissions for Path | sdemirel | NORMAL | 2020-07-20T18:26:37.105155+00:00 | 2020-07-20T18:26:37.105183+00:00 | 602 | false | ```\n// Runtime: 0 ms, faster than 100.00% of Java online submissions for Path Sum.\n// Memory Usage: 39.2 MB, less than 73.39% of Java online submissions for Path Sum.\nclass Solution {\n private boolean answer = false;\n public boolean hasPathSum(TreeNode root, int sum) {\n if(root==null) return false;\n... | 7 | 0 | ['Depth-First Search', 'Java'] | 1 |
path-sum | Java - 0ms - Recursive | java-0ms-recursive-by-horizonhhh-38pt | \n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) | horizonhhh | NORMAL | 2020-02-23T01:28:55.115778+00:00 | 2020-02-23T01:28:55.115831+00:00 | 679 | false | ```\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n public boolean hasPathSum(TreeNode root, int sum) {\n if(root == null)\n return false;\n ... | 7 | 0 | ['Recursion', 'Java'] | 0 |
path-sum | My solution in C++ | my-solution-in-c-by-murdem91-6rjo | /**\n * Definition for binary tree\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeN | murdem91 | NORMAL | 2015-01-04T21:54:52+00:00 | 2015-01-04T21:54:52+00:00 | 1,568 | false | /**\n * Definition for binary tree\n * struct TreeNode {\n * int val;\n * TreeNode *left;\n * TreeNode *right;\n * TreeNode(int x) : val(x), left(NULL), right(NULL) {}\n * };\n */\n class Solution {\n public:\n bool hasPathSum(TreeNode *root, int sum) {\n... | 7 | 0 | [] | 0 |
path-sum | My Java Solution | my-java-solution-by-hsle-wxq8 | public class Solution {\n public boolean hasPathSum(TreeNode root, int sum) {\n if (root == null)\n return false;\n | hsle | NORMAL | 2015-03-26T05:42:32+00:00 | 2015-03-26T05:42:32+00:00 | 984 | false | public class Solution {\n public boolean hasPathSum(TreeNode root, int sum) {\n if (root == null)\n return false;\n if (root.left == null && root.right == null)\n return sum == root.val;\n return hasPathSum(root.left,sum-root.val) || hasPathSum(r... | 7 | 0 | [] | 0 |
path-sum | Solution By Dare2Solve | Detailed Explanation | Clean Code | solution-by-dare2solve-detailed-explanat-95pl | Explanation []\nauthorslog.com/blog/Wj6FZWGWa9\n\n# Code\n\ncpp []\nclass Solution {\npublic:\n bool hasPathSum(TreeNode* root, int targetSum) \n {\n | Dare2Solve | NORMAL | 2024-07-15T18:10:56.721189+00:00 | 2024-07-15T18:10:56.721222+00:00 | 2,437 | false | ```Explanation []\nauthorslog.com/blog/Wj6FZWGWa9\n```\n# Code\n\n```cpp []\nclass Solution {\npublic:\n bool hasPathSum(TreeNode* root, int targetSum) \n {\n if (root == nullptr) {\n return false;\n }\n targetSum -= root->val;\n if (root->left == nullptr && root->right == n... | 6 | 0 | ['Tree', 'Python', 'C++', 'Java', 'Python3', 'JavaScript'] | 0 |
path-sum | ✅ C++ | Easy in 3 lines | c-easy-in-3-lines-by-kosant-pfgl | Code\n\nclass Solution {\npublic:\n bool hasPathSum(TreeNode* root, int targetSum) {\n if (!root) return false;\n if (root->val == targetSum && | kosant | NORMAL | 2023-05-15T07:10:06.146369+00:00 | 2023-05-15T07:10:06.146399+00:00 | 3,781 | false | # Code\n```\nclass Solution {\npublic:\n bool hasPathSum(TreeNode* root, int targetSum) {\n if (!root) return false;\n if (root->val == targetSum && !root->left && !root->right) return true;\n return hasPathSum(root->right, targetSum - root->val) || hasPathSum(root->left, targetSum - root->val);... | 6 | 0 | ['Tree', 'C', 'Binary Tree', 'C++'] | 1 |
path-sum | Easiest Java Solution || Beats 100% || Recursive | easiest-java-solution-beats-100-recursiv-y2ar | Intuition\nIteration of Tree and summing up the path till leaf.\nsearcing the leaf node is equal to target or not.\n\n# Approach\njust like node to leaf sum pro | harshverma2702 | NORMAL | 2023-04-15T05:42:52.959560+00:00 | 2023-04-15T05:42:52.959602+00:00 | 3,488 | false | # Intuition\nIteration of Tree and summing up the path till leaf.\nsearcing the leaf node is equal to target or not.\n\n# Approach\njust like node to leaf sum problem , sum up all path till leaf\nex- \n```\ntree = 1 and target is 11\n / \\\n 2 3\n / / \\\n 5 4 7\n```\n\nso after path... | 6 | 0 | ['Java'] | 0 |
path-sum | My shortest C++ solution | my-shortest-c-solution-by-bishal_722-2sav | \n# Code\nC++ []\nclass Solution {\npublic:\n bool hasPathSum(TreeNode* root, int targetSum) {\n if (!root)\n return false;\n \n | bishal_722 | NORMAL | 2023-03-14T03:12:29.548340+00:00 | 2023-11-05T05:06:33.479436+00:00 | 1,694 | false | \n# Code\n```C++ []\nclass Solution {\npublic:\n bool hasPathSum(TreeNode* root, int targetSum) {\n if (!root)\n return false;\n \n if (root->val == targetSum and !root->left and !root->right)\n return true;\n \n return hasPathSum(root->left, targetSum - root-... | 6 | 0 | ['C++'] | 1 |
path-sum | ✅ Cleanest TypeScript Solution (DFS) | cleanest-typescript-solution-dfs-by-mlaj-j9ef | Code (DFS)\n\nfunction hasPathSum(root: TreeNode | null, targetSum: number): boolean {\n if (!root) return false\n if (!root.left && !root.right && root.v | mlajkim | NORMAL | 2023-02-12T20:27:26.207584+00:00 | 2023-02-12T20:27:26.207627+00:00 | 587 | false | # Code (DFS)\n```\nfunction hasPathSum(root: TreeNode | null, targetSum: number): boolean {\n if (!root) return false\n if (!root.left && !root.right && root.val === targetSum) return true\n\n return hasPathSum(root.left, targetSum - root.val)\n || hasPathSum(root.right, targetSum - root.val)\n};\n``` | 6 | 0 | ['TypeScript'] | 1 |
path-sum | JAVASCRIPT SIMPLE || Up vote if u like | javascript-simple-up-vote-if-u-like-by-v-gktr | Code\n\nvar hasPathSum = function(root, targetSum) {\n if (!root) return false // not a leaf\n if (!root.left && !root.right) return root.val === targetSu | vfyodorov | NORMAL | 2023-01-16T09:01:23.290848+00:00 | 2023-01-16T09:01:23.290894+00:00 | 852 | false | # Code\n```\nvar hasPathSum = function(root, targetSum) {\n if (!root) return false // not a leaf\n if (!root.left && !root.right) return root.val === targetSum; // leaf\n\n return hasPathSum(root.left, targetSum - root.val) || hasPathSum(root.right, targetSum - root.val);\n};\n``` | 6 | 0 | ['JavaScript'] | 0 |
path-sum | 0ms JAVA SOLUTION ANOTHER APPROACH | 0ms-java-solution-another-approach-by-ma-plpd | \n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n | Maheshwari_Saksham | NORMAL | 2023-01-12T09:22:41.071767+00:00 | 2023-01-12T09:22:41.071814+00:00 | 1,205 | false | ```\n/**\n * Definition for a binary tree node.\n * public class TreeNode {\n * int val;\n * TreeNode left;\n * TreeNode right;\n * TreeNode() {}\n * TreeNode(int val) { this.val = val; }\n * TreeNode(int val, TreeNode left, TreeNode right) {\n * this.val = val;\n * this.left = l... | 6 | 0 | ['Tree', 'Java'] | 0 |
path-sum | Python || recursive | python-recursive-by-georgeofgeorgia-kj0o | \nclass Solution:\n def hasPathSum(self, root: Optional[TreeNode], targetSum: int) -> bool:\n def helper(node,tot):\n if not node:\n | georgeofgeorgia | NORMAL | 2022-11-14T08:11:44.723926+00:00 | 2022-11-14T08:11:44.723963+00:00 | 629 | false | ```\nclass Solution:\n def hasPathSum(self, root: Optional[TreeNode], targetSum: int) -> bool:\n def helper(node,tot):\n if not node:\n return \n elif not node.left and not node.right:\n if tot+node.val==targetSum:\n return True\n ... | 6 | 0 | [] | 1 |
path-sum | C++ || Concise recursion || Clean Inorder traversal | c-concise-recursion-clean-inorder-traver-wo78 | \n bool inorder(TreeNode* root , int sum , int &targetSum)\n {\n if(!root) return false;\n sum+=root->val;\n if(root->left==NULL && roo | ashay028 | NORMAL | 2022-10-04T17:26:05.359325+00:00 | 2022-10-04T17:26:05.359363+00:00 | 216 | false | ```\n bool inorder(TreeNode* root , int sum , int &targetSum)\n {\n if(!root) return false;\n sum+=root->val;\n if(root->left==NULL && root->right==NULL) if(sum==targetSum) return true; \n return (inorder(root->left , sum , targetSum) || inorder(root->right , sum , targetSum));\n }\n ... | 6 | 0 | [] | 0 |
path-sum | Java(0ms) || Simple explanation with TC & SC || Easy to understand | java0ms-simple-explanation-with-tc-sc-ea-rkuo | ```\nclass Solution {\n \n public boolean hasPathSum(TreeNode root, int targetSum) {\n \n //return false when root is null or when we reache | Shaikh_Ovais | NORMAL | 2022-07-03T08:59:20.487936+00:00 | 2022-07-03T10:26:27.446622+00:00 | 257 | false | ```\nclass Solution {\n \n public boolean hasPathSum(TreeNode root, int targetSum) {\n \n //return false when root is null or when we reached leaf node but the sum is not equal to target sum\n if(root == null) {\n return false;\n }\n \n //if the current node is... | 6 | 0 | ['Recursion', 'Java'] | 0 |
path-sum | 90 % Faster C++ Solution | 90-faster-c-solution-by-ariyanlaskar-kack | \n bool hasPathSum(TreeNode* root, int targetSum) {\n if(!root){\n return false;\n }\n if(targetSum==root->val && root->left==NU | Ariyanlaskar | NORMAL | 2021-10-31T11:13:43.457057+00:00 | 2021-10-31T11:13:43.457098+00:00 | 402 | false | ```\n bool hasPathSum(TreeNode* root, int targetSum) {\n if(!root){\n return false;\n }\n if(targetSum==root->val && root->left==NULL && root->right==NULL){\n return true;\n }\n return hasPathSum(root->left,targetSum-(root->val)) || hasPathSum(root->right,targetS... | 6 | 0 | ['C'] | 0 |
path-sum | C# DFS Recursive, DFS Iterative and BFS | c-dfs-recursive-dfs-iterative-and-bfs-by-lqy4 | DFS Recursive:\n\n\npublic bool HasPathSum(TreeNode root, int targetSum)\n{\n if(root == null)\n return false;\n \n if(root.left == null && root | akmetainfo | NORMAL | 2021-08-03T21:47:51.885488+00:00 | 2021-08-03T22:05:40.691937+00:00 | 324 | false | DFS Recursive:\n\n```\npublic bool HasPathSum(TreeNode root, int targetSum)\n{\n if(root == null)\n return false;\n \n if(root.left == null && root.right == null)\n return root.val == targetSum;\n \n return HasPathSum(root.left, targetSum - root.val) || HasPathSum(root.right, targetSum - ro... | 6 | 0 | ['Depth-First Search', 'Breadth-First Search', 'Recursion', 'Iterator'] | 0 |
path-sum | Simple recursive Python 3 | simple-recursive-python-3-by-gecko50-735c | Algorithm:\n decrement the sum as you recurse down the binary tree\n if you are at a leaf node, check if sum == 0\n\n\nclass Solution:\n def hasPathSum(self, | gecko50 | NORMAL | 2020-10-15T22:42:42.982024+00:00 | 2020-10-15T22:42:42.982069+00:00 | 963 | false | Algorithm:\n* decrement the sum as you recurse down the binary tree\n* if you are at a leaf node, check if `sum == 0`\n\n```\nclass Solution:\n def hasPathSum(self, root: TreeNode, sum: int) -> bool:\n if not root:\n return False\n\n sum -= root.val\n \n #only check sum if it i... | 6 | 1 | ['Depth-First Search', 'Python', 'Python3'] | 1 |
snakes-and-ladders | C++ || Simple BFS (With Full Explanation)🌚 || Beats 100% 🏁🔥 | c-simple-bfs-with-full-explanation-beats-84jo | Intuition\nThe intuition behind this code is that it uses a breadth-first search (BFS) algorithm to find the minimum number of moves required to reach the last | ufoblivr | NORMAL | 2023-01-24T01:48:13.505668+00:00 | 2023-01-24T15:03:59.589930+00:00 | 38,660 | false | # Intuition\nThe intuition behind this code is that it uses a breadth-first search (BFS) algorithm to find the minimum number of moves required to reach the last cell of the board from the first cell. BFS is an algorithm that explores all the vertices of a graph or all the nodes of a tree level by level.\n\n# Approach\... | 777 | 5 | ['Breadth-First Search', 'C++'] | 10 |
snakes-and-ladders | Diagram and BFS | diagram-and-bfs-by-lee215-xhwv | I drew this diagram.\nHope it help understand the problem.\n(shouldn\'t leetcode note the author?)\n\n\n\nPython:\n\n def snakesAndLadders(self, board):\n | lee215 | NORMAL | 2018-09-23T03:05:22.656545+00:00 | 2020-09-02T14:58:59.438230+00:00 | 55,913 | false | **I drew this diagram.**\nHope it help understand the problem.\n(shouldn\'t leetcode note the author?)\n\n<img alt="" src="https://assets.leetcode.com/users/lee215/image_1537671763.png" style="width: 500px;" />\n\n**Python:**\n```\n def snakesAndLadders(self, board):\n n = len(board)\n need = {1: 0}\n ... | 612 | 22 | [] | 58 |
snakes-and-ladders | Change to 1D array then BFS | change-to-1d-array-then-bfs-by-wangzi614-g6on | \nclass Solution {\n public int snakesAndLadders(int[][] board) {\n int n = board.length;\n int[] arr = new int[n * n];\n int i = n - 1, | wangzi6147 | NORMAL | 2018-09-23T03:15:12.185327+00:00 | 2018-10-26T05:52:31.097447+00:00 | 31,830 | false | ```\nclass Solution {\n public int snakesAndLadders(int[][] board) {\n int n = board.length;\n int[] arr = new int[n * n];\n int i = n - 1, j = 0, index = 0, inc = 1;\n while (index < n * n) {\n arr[index++] = board[i][j];\n if (inc == 1 && j == n - 1) {\n ... | 195 | 2 | [] | 40 |
snakes-and-ladders | Java concise solution easy to understand | java-concise-solution-easy-to-understand-1f6a | \n public int snakesAndLadders(int[][] board) {\n int n = board.length;\n Queue<Integer> queue = new LinkedList<>();\n queue.offer(1);\n | yuxiangmusic | NORMAL | 2018-09-23T20:18:24.673709+00:00 | 2018-10-16T02:23:01.157291+00:00 | 18,274 | false | ```\n public int snakesAndLadders(int[][] board) {\n int n = board.length;\n Queue<Integer> queue = new LinkedList<>();\n queue.offer(1);\n boolean[] visited = new boolean[n * n + 1];\n for (int move = 0; !queue.isEmpty(); move++) {\n for (int size = queue.size(); size >... | 120 | 2 | [] | 17 |
snakes-and-ladders | BFS, intuition, diagrams and tests, c++, 12ms | bfs-intuition-diagrams-and-tests-c-12ms-9hd37 | Intuition: \nFor each step we do the follwoing:\n1. roll a dice (and check all 6 possible values, marking each as visited)\n2. check if we land on a ladder and | savvadia | NORMAL | 2019-10-04T06:28:52.499073+00:00 | 2020-03-10T06:32:28.537616+00:00 | 13,632 | false | Intuition: \nFor each step we do the follwoing:\n1. roll a dice (and check all 6 possible values, marking each as visited)\n2. check if we land on a ladder and take it (no possibility to skip it, we must take it)\n3. remember where to continue next time (add the new position to the queue)\n\nNow let\'s take a look at s... | 106 | 1 | ['Breadth-First Search', 'C'] | 9 |
snakes-and-ladders | Python3 clear BFS solution | python3-clear-bfs-solution-by-jinjiren-4fk1 | Thought process\n- simply apply BFS to find the length of shortest path from 1 to n*n\n- key point is to correctly compute the corresponding coordinates of the | jinjiren | NORMAL | 2019-06-18T04:26:59.148806+00:00 | 2019-06-18T04:26:59.148846+00:00 | 9,256 | false | ## Thought process\n- simply apply BFS to find the length of shortest path from `1` to `n*n`\n- key point is to correctly compute the corresponding coordinates of the label\n- also remember to avoid circle by using a hashset to track visited positions\n- time complexity: O(n^2), n is the width and height of the grid\n-... | 101 | 1 | ['Breadth-First Search', 'Python'] | 11 |
snakes-and-ladders | C++: bfs || detailed explanation || faster than 99.31% | c-bfs-detailed-explanation-faster-than-9-x2o9 | Lets assume number of rows and column is n.\nThe trick is to find the coornidate of the square with number s. If you can find the coordinate of given square wit | bingabid | NORMAL | 2020-08-16T08:40:32.376077+00:00 | 2021-12-25T09:08:40.215142+00:00 | 8,170 | false | Lets assume number of rows and column is n.\nThe trick is to find the coornidate of the square with number s. If you can find the coordinate of given square with number s then it\'s just a plain vanilla bfs. Since rows are starting from bottom, just dividing \'s\' by \'n\' won\'t work. So, to get actual rows from botto... | 94 | 0 | [] | 14 |
snakes-and-ladders | Day 24 || Easiest Beginner Friendly Solution || O(n^2) time and O(n^2) space | day-24-easiest-beginner-friendly-solutio-e5kp | Intuition\nThis problem contains simple BFS but the main intution of this problem to find cordinates of particular value i.e. row and column.\n1. the variable " | singhabhinash | NORMAL | 2023-01-24T02:54:46.655093+00:00 | 2023-01-24T05:08:00.840981+00:00 | 9,439 | false | # Intuition\nThis problem contains simple BFS but the main intution of this problem to find cordinates of particular value i.e. row and column.\n1. the variable "row" is calculated by subtracting the quotient of (curr-1) / n from n-1. This is done to convert the 1-indexed position of the element to a 0-indexed position... | 87 | 0 | ['Breadth-First Search', 'Python', 'C++', 'Java'] | 3 |
snakes-and-ladders | ✅Short || C++ || Java || PYTHON || JS || Explained Solution✔️ || Beginner Friendly ||🔥 | short-c-java-python-js-explained-solutio-em3c | Read Fulll Article for code and Explanination...\nhttps://www.nileshblog.tech/leetcode-solving-snakes-and-ladders-with-bfs-algorithm/\n\n\n\n\nRead Both Solutio | amoddeshmukh844 | NORMAL | 2023-01-24T03:43:25.640219+00:00 | 2023-03-10T05:19:30.548232+00:00 | 10,587 | false | Read Fulll Article for code and Explanination...\nhttps://www.nileshblog.tech/leetcode-solving-snakes-and-ladders-with-bfs-algorithm/\n\n\n\n\nRead Both Solution .\n\nSolution 1:BFS**\n**\nTime Complexit o(n^2) space - O(n)\n\n\n.png](https://assets.leetcode.com/users/images/7d6489c3-f9cc-4c5b-a1a1-a18dfe042adb_1674559168.4547062.png)\nstep 1) we can go at 6 locati... | 52 | 1 | ['C++'] | 3 |
snakes-and-ladders | 🔥Easy Explanation🔥 with Diagram | Java | easy-explanation-with-diagram-java-by-je-ture | Intuition\n Describe your first thoughts on how to solve this problem. \n\n\nLets forget about the 2d array its confusing. Lets get into game.\nI am playing gam | jeevankumar159 | NORMAL | 2023-01-24T03:14:46.648501+00:00 | 2023-01-24T15:00:08.744815+00:00 | 4,890 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n\nLets forget about the 2d array its confusing. Lets get into game.\nI am playing game, I sa... | 41 | 2 | ['Java'] | 3 |
snakes-and-ladders | 🚀Beats 100%(2ms)🚀 ||✅Easy Solutions✅||🔥Fully Explained🔥|| C++|| Java|| Python3 | beats-1002ms-easy-solutionsfully-explain-wcf2 | Intuition :\n 1. For each step we do the following:\n\n - roll dice (and check all 6 possible values, marking each as visited)\n - check if we land on a l | N7_BLACKHAT | NORMAL | 2023-01-24T05:09:28.286983+00:00 | 2023-01-24T05:25:04.278402+00:00 | 7,629 | false | # Intuition :\n 1. For each step we do the following:\n\n - roll dice (and check all 6 possible values, marking each as visited)\n - check if we land on a ladder and take it (no possibility to skip it, we must take it)\n - remember where to continue next time (add the new position to the queue)\n2. Now let\u20... | 40 | 1 | ['Heap (Priority Queue)', 'Python', 'C++', 'Java', 'Python3'] | 4 |
snakes-and-ladders | [c++] bfs easy solution with explanation | c-bfs-easy-solution-with-explanation-by-ib599 | \n\tpair<int, int> coordinates(int x, int n) // find the coordinates given integer\n {\n int r = n - (x-1)/n -1;\n int c = (x-1)%n;\n if | prateekchhikara | NORMAL | 2020-07-06T16:59:53.192444+00:00 | 2020-07-06T17:02:23.651808+00:00 | 4,095 | false | ```\n\tpair<int, int> coordinates(int x, int n) // find the coordinates given integer\n {\n int r = n - (x-1)/n -1;\n int c = (x-1)%n;\n if(r%2==n%2)\n return {r,n-c-1};\n return {r, c};\n }\n int snakesAndLadders(vector<vector<int>>& board) {\n int steps = 0;\n ... | 37 | 0 | [] | 10 |
snakes-and-ladders | C++ solution with detailed explanation | c-solution-with-detailed-explanation-by-gkpf3 | \nNote that u are starting from the bottom and u change the direction after finishing every row.\nApproach used here is BFS.\nWe push the start(1) to our queue | leodicap99 | NORMAL | 2020-05-12T02:56:17.587544+00:00 | 2020-05-12T02:56:17.587611+00:00 | 4,024 | false | ```\nNote that u are starting from the bottom and u change the direction after finishing every row.\nApproach used here is BFS.\nWe push the start(1) to our queue and proceed with our BFS.\nWe will explore all the six sides and keep moving forward until I reach r*r where r is the size of the board.\n\nApart from the st... | 29 | 1 | ['Breadth-First Search', 'C', 'C++'] | 3 |
snakes-and-ladders | Clean concise easy under-standing solution bfs c++ | clean-concise-easy-under-standing-soluti-61vy | \n int snakesAndLadders(vector<vector<int>>& board) {\n int n=board.size();\n vector<vector<bool>> visited(n , vector<bool>(n,false));\n \n | ladyengg | NORMAL | 2021-06-02T15:11:02.027151+00:00 | 2021-06-02T15:11:02.027201+00:00 | 2,362 | false | ```\n int snakesAndLadders(vector<vector<int>>& board) {\n int n=board.size();\n vector<vector<bool>> visited(n , vector<bool>(n,false));\n \n queue<int> q;\n q.push(1);\n visited[n-1][0]=true;\n int steps=0;\n while(!q.empty())\n {\n int size=q.... | 28 | 1 | ['Breadth-First Search', 'C'] | 2 |
snakes-and-ladders | Clean Java Solution - BFS | clean-java-solution-bfs-by-mycafebabe-yzjc | \nclass Solution {\n public int snakesAndLadders(int[][] board) {\n if (board == null || board.length == 0 || board[0].length == 0) {\n ret | mycafebabe | NORMAL | 2019-01-05T21:00:12.638230+00:00 | 2019-01-05T21:00:12.638282+00:00 | 4,486 | false | ```\nclass Solution {\n public int snakesAndLadders(int[][] board) {\n if (board == null || board.length == 0 || board[0].length == 0) {\n return -1;\n }\n int rows = board.length;\n int cols = board[0].length;\n int dest = rows * cols;\n Queue<Integer> queue = ne... | 25 | 0 | [] | 8 |
snakes-and-ladders | Python BFS solution | python-bfs-solution-by-cenkay-o5ng | \nclass Solution:\n def snakesAndLadders(self, board):\n arr, nn, q, seen, moves = [0], len(board) ** 2, [1], set(), 0\n for i, row in enumerat | cenkay | NORMAL | 2018-09-23T19:24:05.419788+00:00 | 2018-09-23T19:24:05.419831+00:00 | 3,708 | false | ```\nclass Solution:\n def snakesAndLadders(self, board):\n arr, nn, q, seen, moves = [0], len(board) ** 2, [1], set(), 0\n for i, row in enumerate(board[::-1]): arr += row[::-1] if i % 2 else row\n while q:\n new = []\n for sq in q:\n if sq == nn: return mov... | 24 | 1 | [] | 8 |
snakes-and-ladders | Python 3 || 16 lines, w/ brief comments || T/S: 98% / 96% | python-3-16-lines-w-brief-comments-ts-98-7pom | \nclass Solution:\n def snakesAndLadders(self, board: List[List[int]]) -> int:\n \n board.reverse() # <\u2 | Spaulding_ | NORMAL | 2023-01-24T04:44:02.113790+00:00 | 2024-05-31T17:04:28.296456+00:00 | 3,762 | false | ```\nclass Solution:\n def snakesAndLadders(self, board: List[List[int]]) -> int:\n \n board.reverse() # <\u2013\u2013 convert the board to 1D list\n for i in range(1,len(board),2): board[i].reverse()\n arr = [None]+list(chain(*board)) ... | 22 | 0 | ['Python3'] | 2 |
snakes-and-ladders | DFS vs BFS vs Djikstra solution. C++ | dfs-vs-bfs-vs-djikstra-solution-c-by-adi-n5ze | Conventional wisdom(and most textbooks) say that for finding shortest path in a graph, you use BFS for unweighted graph and you use Djikstra\'s algorithm for we | aditya991 | NORMAL | 2021-07-05T23:34:02.022478+00:00 | 2021-07-06T04:53:27.253166+00:00 | 2,597 | false | Conventional wisdom(and most textbooks) say that for finding shortest path in a graph, you use BFS for unweighted graph and you use Djikstra\'s algorithm for weighted graphs. But they don\'t say that you cannot use BFS, DFS on weighted graphs. You can modify those algorithms to find the shortest path in weighted graphs... | 22 | 0 | ['Depth-First Search', 'Breadth-First Search', 'C'] | 6 |
snakes-and-ladders | ⭐ C++ solution || BFS || faster than 98% || with Explanation | c-solution-bfs-faster-than-98-with-expla-ivvn | Intuition\nThe problem is asking us to find the minimum number of moves required to reach the end of a board game represented by a 2D grid (snakes and ladders g | rvdd | NORMAL | 2023-01-24T02:50:10.009274+00:00 | 2023-01-24T12:35:21.942040+00:00 | 6,962 | false | # Intuition\nThe problem is asking us to find the minimum number of moves required to reach the end of a board game represented by a 2D grid (snakes and ladders game). The key observation here is that the board can be represented by a 1D array, where each element in the array corresponds to a cell in the 2D grid. This ... | 20 | 0 | ['Array', 'Breadth-First Search', 'C++'] | 3 |
snakes-and-ladders | ⭐✅ WORKING C++ CODE || SELF EXPLANATORY COMMENTS | working-c-code-self-explanatory-comments-u35a | WORKING C++ CODE || SELF EXPLANATORY COMMENTS || Inspired by wangzi6147\n\n\nclass Solution {\npublic:\n int snakesAndLadders(vector<vector<int>>& board) {\n | SachinSahu | NORMAL | 2022-07-07T03:57:00.644625+00:00 | 2022-12-23T17:27:08.946816+00:00 | 1,106 | false | WORKING C++ CODE || SELF EXPLANATORY COMMENTS || Inspired by wangzi6147\n\n```\nclass Solution {\npublic:\n int snakesAndLadders(vector<vector<int>>& board) {\n \n int n = board.size();\n \n int arr[n*n]; // 1D array of size n^2\n \n int i = n-1, j = 0; // starting pos\... | 18 | 0 | ['Breadth-First Search', 'C', 'C++'] | 1 |
snakes-and-ladders | Java - Easy Solution with comments (Change board to map + BFS) | java-easy-solution-with-comments-change-615kc | \nclass Solution {\n public int snakesAndLadders(int[][] board) {\n //Step1: Convert board to hashmap to map the board cell number to cell value for e | meltawab | NORMAL | 2020-09-09T02:26:24.838496+00:00 | 2020-09-09T02:26:24.838546+00:00 | 1,943 | false | ```\nclass Solution {\n public int snakesAndLadders(int[][] board) {\n //Step1: Convert board to hashmap to map the board cell number to cell value for easier calculation\n int n = board.length;\n HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();\n int start = n * n;\n ... | 17 | 0 | ['Breadth-First Search', 'Java'] | 1 |
snakes-and-ladders | Concise java solution explained without use of complex function to get vertex everytime. | concise-java-solution-explained-without-ysxvp | Following links were very helpful in making me understand the logic of this question.\n1) Covers algorithmn via video \n2) Go through this quicky \n3) To cl | nikeMafia | NORMAL | 2020-02-26T21:05:21.175435+00:00 | 2022-10-21T19:13:32.184319+00:00 | 1,095 | false | Following links were very helpful in making me understand the logic of this question.\n1) [Covers algorithmn via video](https://www.youtube.com/watch?v=1pMNYQmtVVg) \n2) [Go through this quicky](https://www.techiedelight.com/min-throws-required-to-win-snake-and-ladder-game/) \n3) To clear your question properly and... | 16 | 1 | ['Breadth-First Search', 'Java'] | 1 |
snakes-and-ladders | 🔥 [LeetCode The Hard Way] 🔥 Explained Line By Line | leetcode-the-hard-way-explained-line-by-le34u | \uD83D\uDD34 Check out LeetCode The Hard Way for more solution explanations and tutorials. \n\uD83D\uDFE0 Check out our Discord for live discussion.\n\uD83D\uDF | __wkw__ | NORMAL | 2023-01-24T04:43:04.295030+00:00 | 2023-01-24T04:43:04.295070+00:00 | 1,301 | false | \uD83D\uDD34 Check out [LeetCode The Hard Way](https://wingkwong.github.io/leetcode-the-hard-way/) for more solution explanations and tutorials. \n\uD83D\uDFE0 Check out our [Discord](https://discord.gg/Nqm4jJcyBf) for live discussion.\n\uD83D\uDFE2 Give a star on [Github Repository](https://github.com/wingkwong/leetco... | 15 | 0 | ['Breadth-First Search', 'C++'] | 1 |
snakes-and-ladders | JAVA || EASY UNDERSTANDING || BFS || SIMPLE || WITH COMMENTS | java-easy-understanding-bfs-simple-with-k2q9q | Code\n\nclass Solution {\n public int snakesAndLadders(int[][] board) {\n int n=board.length;\n Map<Integer,Integer>hm=new HashMap<>();\n | shaikhu3421 | NORMAL | 2023-01-24T04:12:35.359465+00:00 | 2023-01-24T04:12:35.359500+00:00 | 2,776 | false | # Code\n```\nclass Solution {\n public int snakesAndLadders(int[][] board) {\n int n=board.length;\n Map<Integer,Integer>hm=new HashMap<>();\n hm.put(1,0);//as we are starting from 1st position so we are adding 1 and the number of steps taken are 0\n Queue<Integer>q=new LinkedList<>();\n ... | 15 | 1 | ['Breadth-First Search', 'Java'] | 5 |
snakes-and-ladders | Javascript BFS | javascript-bfs-by-hakuin-2hkf | \nvar snakesAndLadders = function(board) {\n const N = board.length;\n const getLoc = (pos) => {\n let row = Math.floor((pos - 1) / N);\n let col = (pos | hakuin | NORMAL | 2019-05-16T23:23:16.238797+00:00 | 2019-05-16T23:23:16.238831+00:00 | 2,027 | false | ```\nvar snakesAndLadders = function(board) {\n const N = board.length;\n const getLoc = (pos) => {\n let row = Math.floor((pos - 1) / N);\n let col = (pos - 1) % N;\n col = (row % 2) === 1 ? N - col - 1 : col;\n row = N - row - 1;\n return [row,col];\n }\n const q = [1];\n const v = {\'1\': 0};\n ... | 15 | 0 | ['Breadth-First Search', 'JavaScript'] | 0 |
snakes-and-ladders | Python Easy To Understand Code + Explanation O(N) | python-easy-to-understand-code-explanati-3dlz | We do bfs so we can find the smallest number of turns we need to win the game. Any time we are looking for shortest path, we should do bfs. \n\nThe tricky parts | rosemelon | NORMAL | 2019-06-10T02:53:51.205372+00:00 | 2019-06-10T02:53:51.205423+00:00 | 1,453 | false | We do bfs so we can find the smallest number of turns we need to win the game. Any time we are looking for shortest path, we should do bfs. \n\nThe tricky parts here are how the snakes board is initialized. You\'ll notice that we start 1 on the last row instead of the 1st, and that the order of the rows alternate (ie, ... | 13 | 1 | [] | 2 |
snakes-and-ladders | Image Explanation🏆- [Complete Intuition - Simple BFS] - C++/Java | image-explanation-complete-intuition-sim-ulzm | Video Solution (Aryan Mittal) - Link in LeetCode Profile\nSnakes and Ladders by Aryan Mittal\n\n\n\n# Approach & Intution\n\n\n\n\n\n\n\n\n\n\n\n# Code\nC++ []\ | aryan_0077 | NORMAL | 2023-04-09T16:02:09.453506+00:00 | 2023-04-09T16:05:17.258495+00:00 | 1,241 | false | # Video Solution (`Aryan Mittal`) - Link in LeetCode Profile\n`Snakes and Ladders` by `Aryan Mittal`\n\n\n\n# Approach & Intution\n {\n int n = board.size();\n vector<int> fla | coding_menance | NORMAL | 2023-01-24T04:30:40.663087+00:00 | 2023-01-24T04:30:40.663139+00:00 | 1,239 | false | # Solution Code\n``` C++ []\nclass Solution {\npublic:\n int snakesAndLadders(vector<vector<int>>& board) {\n int n = board.size();\n vector<int> flattenedBoard(n * n);\n int index = 0;\n bool leftToRight = true;\n for (int i = n - 1; i >= 0; i--) {\n if (leftToRight) {\n for... | 12 | 1 | ['C++'] | 1 |
snakes-and-ladders | C++ || Good Code Quality || BFS Solution and Why DFS won't work ? | c-good-code-quality-bfs-solution-and-why-ymmt | Intuition\nThis problem if we break it down we can easily observe we need a shortest path from 1 to $n^2$ with least moves. For such a problem we tend to use BF | akgupta0777 | NORMAL | 2023-01-24T09:54:18.338213+00:00 | 2024-05-05T05:49:04.520561+00:00 | 717 | false | # Intuition\nThis problem if we break it down we can easily observe we need a shortest path from 1 to $n^2$ with least moves. For such a problem we tend to use BFS or Dijkstra but building a graph for dijkstra is complex so I decided to use BFS since we can use it on matrix as well.\n\n# Approach\nWe maintain a standar... | 11 | 0 | ['Array', 'Depth-First Search', 'Breadth-First Search', 'Matrix', 'C++'] | 2 |
snakes-and-ladders | ✅C++/JAVA/Python |BFS | Very Simple ✔ | cjavapython-bfs-very-simple-by-xahoor72-enov | Intuition\n Describe your first thoughts on how to solve this problem. \nSimply think of shortest path algo i.e bfs or we can do dijkstra\'s algo .That is what | Xahoor72 | NORMAL | 2023-01-24T10:37:58.379201+00:00 | 2023-01-24T10:46:51.969938+00:00 | 1,046 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSimply think of shortest path algo i.e bfs or we can do dijkstra\'s algo .That is what we have to do here. For every cell there are 6 possiblilies (dice) so we check the all 6 steps which one will bring us shortest path will take that.And... | 10 | 0 | ['Array', 'Breadth-First Search', 'Matrix', 'C++'] | 1 |
snakes-and-ladders | 100% fast javascript very easy to understand with video explanation! | 100-fast-javascript-very-easy-to-underst-t16z | If you like my video and explanation, Subscribe please!!! Thank you!!\n\nhttps://youtu.be/i91nezWtI7Y\n\n\n\n\n# Code\n\n/**\n * @param {number[][]} board\n * @ | rlawnsqja850 | NORMAL | 2023-01-24T01:49:33.756745+00:00 | 2023-01-24T01:49:33.756775+00:00 | 1,397 | false | If you like my video and explanation, Subscribe please!!! Thank you!!\n\nhttps://youtu.be/i91nezWtI7Y\n\n\n\n\n# Code\n```\n/**\n * @param {number[][]} board\n * @return {number}\n */\nvar snakesAndLadders ... | 10 | 0 | ['JavaScript'] | 3 |
snakes-and-ladders | 📌📌Python3 || ⚡122 ms, faster than 75.83% of Python3 | python3-122-ms-faster-than-7583-of-pytho-g7kc | \ndef snakesAndLadders(self, board: List[List[int]]) -> int:\n n = len(board)\n board.reverse()\n\n def intToPos(square):\n r = | harshithdshetty | NORMAL | 2023-01-24T03:18:10.653284+00:00 | 2023-01-24T03:18:10.653319+00:00 | 1,847 | false | ```\ndef snakesAndLadders(self, board: List[List[int]]) -> int:\n n = len(board)\n board.reverse()\n\n def intToPos(square):\n r = (square - 1) // n\n c = (square - 1) % n\n if r % 2:\n c = n - 1 - c\n return [r, c]\n\n q = deque()\n... | 9 | 0 | ['Python', 'Python3'] | 2 |
snakes-and-ladders | C++ || Explained with comments || BFS | c-explained-with-comments-bfs-by-chandan-5tse | Upvote if you found solution helpful\nC++\nclass Solution {\npublic:\n\tint snakesAndLadders(vector<vector<int>>& board) {\n\t\tint destination = pow(board.size | chandan93 | NORMAL | 2022-06-05T07:45:33.970196+00:00 | 2022-06-05T07:45:33.970233+00:00 | 576 | false | **Upvote if you found solution helpful**\n```C++\nclass Solution {\npublic:\n\tint snakesAndLadders(vector<vector<int>>& board) {\n\t\tint destination = pow(board.size(), 2);\n\t\tint n = board.size();\n\n\t\tint ans = 0;\n\t\t// creating a hashtable for maintaining which cell is visited already\n\t\tunordered_set<int... | 9 | 1 | ['Breadth-First Search', 'C'] | 0 |
snakes-and-ladders | [PYTHON] Easy Understanding solution ✔ | python-easy-understanding-solution-by-ra-96uk | The solution may be lengthy but it is readable, fast and easy to understand, dry run it you will surely get the logic its guarantee if still doubt arises ask in | RaghavGupta22 | NORMAL | 2022-04-09T10:09:28.620257+00:00 | 2022-05-08T07:39:53.154285+00:00 | 1,908 | false | The solution may be lengthy but it is readable, fast and easy to understand, dry run it you will surely get the logic its guarantee if still doubt arises ask in comments. \n\n\tclass Solution:\n\t\tdef snakesAndLadders(self, board: List[List[int]]) -> int:\n\t\t\tn=len(board)\n\t\t\tstart, end =1,n*n\n\t\t\tvisited=set... | 9 | 0 | ['Breadth-First Search', 'Python', 'Python3'] | 4 |
snakes-and-ladders | ✅ JAVA || BFS || CLEAND CONCISE READABLE || | java-bfs-cleand-concise-readable-by-bhar-u5sv | THIS QUESTION IS SIMILAR TO ROTTEN ORANGES PROBLEM.THE ONLY CHANGE IS YOU HAVE TO FIND THE ROW AND COLUMN WHICH IS THE HARDEST PART IN THIS QUESTION.TO FIND THE | bharathkalyans | NORMAL | 2022-03-10T06:14:03.345571+00:00 | 2022-03-10T06:14:34.868499+00:00 | 1,174 | false | **THIS QUESTION IS SIMILAR TO ROTTEN ORANGES PROBLEM.THE ONLY CHANGE IS YOU HAVE TO FIND THE ROW AND COLUMN WHICH IS THE HARDEST PART IN THIS QUESTION.TO FIND THE ROW AND COLUMN WE HAVE TO TRY HIT AND TRY METHOD AND COME TO CONCLUSION.\uD83D\uDD25**\n```\nclass Solution {\n public int snakesAndLadders(int[][] board)... | 9 | 0 | ['Breadth-First Search', 'Java'] | 1 |
snakes-and-ladders | Solution By Dare2Solve | Detailed Explanation | Clean Code | solution-by-dare2solve-detailed-explanat-pz5o | Exalanation []\nauthorslog.com/blog/avyU0ff8Pi\n\n# Code\n\ncpp []\nclass Solution {\npublic:\n int snakesAndLadders(vector<vector<int>>& board) {\n i | Dare2Solve | NORMAL | 2024-07-19T17:39:13.898754+00:00 | 2024-07-19T17:39:13.898785+00:00 | 1,459 | false | ```Exalanation []\nauthorslog.com/blog/avyU0ff8Pi\n```\n# Code\n\n```cpp []\nclass Solution {\npublic:\n int snakesAndLadders(vector<vector<int>>& board) {\n int n = board.size();\n set<int> visited;\n auto getPos = [&](int pos) {\n int row = (pos - 1) / n;\n int col = (pos... | 8 | 0 | ['Graph', 'Python', 'C++', 'Java', 'Python3', 'JavaScript'] | 0 |
snakes-and-ladders | java DFS | java-dfs-by-00_11_00-19n6 | \nclass Solution {\n public int snakesAndLadders(int[][] board) {\n int n = board.length;\n \n int[] moves = new int[n * n + 1];\n | 00_11_00 | NORMAL | 2019-03-29T06:30:49.155710+00:00 | 2019-03-29T06:30:49.155758+00:00 | 969 | false | ```\nclass Solution {\n public int snakesAndLadders(int[][] board) {\n int n = board.length;\n \n int[] moves = new int[n * n + 1];\n Arrays.fill(moves, Integer.MAX_VALUE);\n moves[1] = 0;\n \n dfs(1, moves, board);\n return moves[n * n] == Integer.MAX_VALUE? -... | 8 | 0 | [] | 1 |
snakes-and-ladders | Java || BFS | java-bfs-by-henryzhc-kc5u | \n//The most tricky part is to find the current number row and col\nint r = n - 1 - (num - 1) / n;\nint c = r % 2 != n % 2 ? (num - 1) % n : n - 1 - (num - 1) % | henryzhc | NORMAL | 2023-01-24T02:00:15.657790+00:00 | 2023-01-24T02:00:28.499422+00:00 | 1,606 | false | ```\n//The most tricky part is to find the current number row and col\nint r = n - 1 - (num - 1) / n;\nint c = r % 2 != n % 2 ? (num - 1) % n : n - 1 - (num - 1) % n;\n```\n```\nclass Solution {\n public int snakesAndLadders(int[][] board) {\n int n = board.length;\n boolean[] seen = new boolean[n * n ... | 7 | 0 | ['Breadth-First Search', 'Java'] | 1 |
snakes-and-ladders | ✔ [C++] Solution for 909. Snakes and Ladders | c-solution-for-909-snakes-and-ladders-by-3vqe | \nclass Solution {\npublic:\n int snakesAndLadders(vector<vector<int>>& board) \n {\n int sz = board.size(); int target = sz * sz ;\n unorde | utcarsh | NORMAL | 2022-01-05T05:36:56.309498+00:00 | 2022-01-05T05:36:56.309543+00:00 | 884 | false | ```\nclass Solution {\npublic:\n int snakesAndLadders(vector<vector<int>>& board) \n {\n int sz = board.size(); int target = sz * sz ;\n unordered_map<int, int> moves; \n moves[1] = 0; // Zero(No) moves when we are in square 1\n queue<int> q ; q.push(1); //BFS method\n \n ... | 7 | 1 | ['Breadth-First Search', 'C', 'C++'] | 1 |
snakes-and-ladders | [Java] Optimised BFS solution - 2ms (faster than 100%) | java-optimised-bfs-solution-2ms-faster-t-vm2j | The solution is simple BFS where from any square we only visit:\n Snakes or ladders (<= 6 squares away)\n The furthest square without a snake or ladder (<= 6 sq | edlilkid | NORMAL | 2020-11-15T12:55:30.417395+00:00 | 2020-11-15T12:56:23.929916+00:00 | 1,056 | false | The solution is simple BFS where from any square we **only** visit:\n* Snakes or ladders (<= 6 squares away)\n* The furthest square **without** a snake or ladder (<= 6 squares away)\n\nThere is nothing to be gained from visited unoccupied squares *closer* than the furthest unoccupied square. Even when just visiting the... | 7 | 0 | ['Breadth-First Search', 'Java'] | 1 |
snakes-and-ladders | C++ || BFS || Full Explanation | c-bfs-full-explanation-by-7oskaa-k5la | Intuition\nMake a bfs from $1$ to $N^2$\n\n# Approach\nIf we store the min dist for each value we will get the answer\n\n- First we want to store the coordinate | 7oskaa | NORMAL | 2023-01-24T05:34:14.969652+00:00 | 2023-01-24T05:34:14.969697+00:00 | 393 | false | # Intuition\nMake a bfs from $1$ to $N^2$\n\n# Approach\nIf we store the min dist for each value we will get the answer\n\n- First we want to store the coordinate for each value to can access it\n- For each value we will try the 6 possible destinations for it if they are exist\n- If there is a snake of ladder in the ne... | 6 | 0 | ['Breadth-First Search', 'Graph', 'Matrix', 'C++'] | 0 |
snakes-and-ladders | Java🔥| Explanation + FollowUp Questions🔥✅| Easy | | java-explanation-followup-questions-easy-05a6 | Intuition\n Describe your first thoughts on how to solve this problem. \nThis solution covers all these followups:\n- Minimum Steps to reach the ending point\n- | Sanchit_Jain | NORMAL | 2023-09-05T11:46:17.299334+00:00 | 2023-09-05T11:49:18.941292+00:00 | 288 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis solution covers all these followups:\n- Minimum Steps to reach the ending point\n- What if we have a special dice\n- What if we need to know how many ladders or snakes we have used to reach the destination with minimum Steps\n- Diffe... | 5 | 0 | ['Array', 'Hash Table', 'Breadth-First Search', 'Java'] | 0 |
snakes-and-ladders | ✅✔️Easy and Clean Implementation using BFS || C++ Solution✈️✈️✈️✈️✈️ | easy-and-clean-implementation-using-bfs-81f8b | 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 | ajay_1134 | NORMAL | 2023-08-31T13:28:56.216134+00:00 | 2023-08-31T13:28:56.216180+00:00 | 155 | 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)$$ --... | 5 | 0 | ['Hash Table', 'Breadth-First Search', 'Matrix', 'C++'] | 1 |
snakes-and-ladders | JAVA | BFS | Explained using comments ✅ | java-bfs-explained-using-comments-by-sou-vuhz | Please Upvote \uD83D\uDE07\n---\n\njava []\nclass Solution {\n public int snakesAndLadders(int[][] board) {\n int n = board.length;\n Queue<Int | sourin_bruh | NORMAL | 2023-01-24T08:46:36.951832+00:00 | 2023-01-24T08:54:15.209791+00:00 | 337 | false | # Please Upvote \uD83D\uDE07\n---\n\n``` java []\nclass Solution {\n public int snakesAndLadders(int[][] board) {\n int n = board.length;\n Queue<Integer> q = new LinkedList<>();\n q.offer(1); // we start from the bottom-left cell\n boolean[][] visited = new boolean[n][n];\n vi... | 5 | 0 | ['Array', 'Breadth-First Search', 'Matrix', 'Java'] | 1 |
snakes-and-ladders | [Python] BFS can solve the problem; Explained | python-bfs-can-solve-the-problem-explain-fkms | This is a simple BFS problem.\nWhat we need to take care is:\n(1) how to find the next cell of each movement: whenever there is a ladder or snake, we need to ad | wangw1025 | NORMAL | 2023-01-24T05:59:05.034641+00:00 | 2023-01-24T05:59:05.034683+00:00 | 2,491 | false | This is a simple BFS problem.\nWhat we need to take care is:\n(1) how to find the next cell of each movement: whenever there is a ladder or snake, we need to advance to the next cell;\n(2) how to correctly map the cell index to the (row, col) pair\n\nSee the details in code:\n\n```\nclass Solution:\n def snakesAndLa... | 5 | 0 | ['Breadth-First Search', 'Python3'] | 0 |
snakes-and-ladders | C++ || Easy to Understand || BFS | c-easy-to-understand-bfs-by-mohakharjani-mtq5 | \nclass Solution {\npublic:\n int bfs(map<int, int>&mp, int n, int start)\n {\n queue<int>q;\n q.push(start);\n set<int>visited; \n | mohakharjani | NORMAL | 2023-01-24T01:14:40.286633+00:00 | 2023-08-02T02:37:12.046762+00:00 | 3,396 | false | ```\nclass Solution {\npublic:\n int bfs(map<int, int>&mp, int n, int start)\n {\n queue<int>q;\n q.push(start);\n set<int>visited; \n visited.insert(start);\n int steps = 0;\n //==================================================\n while(!q.empty())\n {\n ... | 5 | 0 | ['Breadth-First Search', 'C', 'C++'] | 2 |
snakes-and-ladders | Snakes and Ladder | Java concise solution easy to understand 100% | snakes-and-ladder-java-concise-solution-r8ru5 | \n\nclass Solution {\n public int snakesAndLadders(int[][] board) {\n int n = board.length;\n boolean visited[][] = new boolean[n][n];\n Qu | shagungoyal | NORMAL | 2022-09-12T15:48:26.561898+00:00 | 2023-01-24T04:19:50.126458+00:00 | 538 | false | \n```\nclass Solution {\n public int snakesAndLadders(int[][] board) {\n int n = board.length;\n boolean visited[][] = new boolean[n][n];\n Queue<Integer> queue = new LinkedList<>();\n queue.add(1);\n visited[n-1][0]=true;\n int steps=0;\n while(!queue.isEmpty()){\n ... | 5 | 1 | ['Breadth-First Search', 'Graph', 'Java'] | 2 |
snakes-and-ladders | Python BFS + 1D array | python-bfs-1d-array-by-ermolushka2-533a | ```\nfrom collections import deque\n\nclass Solution(object):\n def snakesAndLadders(self, arr):\n """\n :type board: List[List[int]]\n | ermolushka2 | NORMAL | 2020-07-16T16:35:45.231290+00:00 | 2020-07-16T16:35:45.231339+00:00 | 605 | false | ```\nfrom collections import deque\n\nclass Solution(object):\n def snakesAndLadders(self, arr):\n """\n :type board: List[List[int]]\n :rtype: int\n """\n \n temp = []\n even = True\n for i in range(len(arr)-1, -1, -1):\n if even:\n t... | 5 | 1 | ['Breadth-First Search', 'Python'] | 3 |
snakes-and-ladders | ✅✅Beats 100%🔥C++🔥Python|| 🚀🚀Super Simple and Efficient Solution🚀🚀||🔥Python🔥C++✅✅ | beats-100cpython-super-simple-and-effici-jk47 | IntuitionTo solve this problem, we employ a Breadth-First Search (BFS) algorithm. BFS is a suitable approach here because it is excellent for finding the shorte | shobhit_yadav | NORMAL | 2025-02-18T00:50:06.578936+00:00 | 2025-02-18T00:50:06.578936+00:00 | 737 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
To solve this problem, we employ a Breadth-First Search (BFS) algorithm. BFS is a suitable approach here because it is excellent for finding the shortest path in an unweighted graph, which essentially our game board is. Each roll of the die... | 4 | 0 | ['Array', 'Breadth-First Search', 'Matrix', 'C++', 'Python3'] | 0 |
snakes-and-ladders | Basic BFS traversal w/ steps processed in batches | basic-bfs-traversal-w-steps-processed-in-19sq | Intuition\n- Use BFS to to simulate an expanding set of moves starting at square 1\n- When the BFS reaches the last location, you have reached the end\n- In gra | zeddic | NORMAL | 2023-06-19T23:28:42.414407+00:00 | 2023-06-19T23:28:42.414424+00:00 | 216 | false | # Intuition\n- Use BFS to to simulate an expanding set of moves starting at square 1\n- When the BFS reaches the last location, you have reached the end\n- In graph traversal problems, questions that ask for the "minimal" number of moves hint a BFS traversal as an option\n- When doing the BFS you have two options of tr... | 4 | 0 | ['TypeScript'] | 1 |
snakes-and-ladders | BFS Intuition and Approach explained! Code with comments | C++ | HashMap | bfs-intuition-and-approach-explained-cod-aicr | Intuition:\n \tWhenever there\'s a problem that has the word \'minimim\' the problem could be of the following categories:\nDP/ Greedy/ BFS but as there was a g | adityabijapurkar | NORMAL | 2023-01-24T07:21:49.395980+00:00 | 2023-01-24T07:21:49.396014+00:00 | 156 | false | ***Intuition:***\n* \tWhenever there\'s a problem that has the word \'minimim\' the problem could be of the following categories:\nDP/ Greedy/ BFS but as there was a grid (or a graph) involved, it could be considered as a BFS problem\n\n***Approach:***\n* Only if we could get the \'x\' and \'y\' indices of the current ... | 4 | 0 | ['Breadth-First Search', 'Graph', 'C', 'C++'] | 0 |
snakes-and-ladders | C++ | BFS | Approach Easy Explained | Board modification Explained | c-bfs-approach-easy-explained-board-modi-iqd5 | class Solution {\npublic:\n //\n //Time complexity is O(n2) as we are using a visited array, otherwise exponential 6^n\n \n //we create a map of sna | jprathamesh | NORMAL | 2022-09-08T04:40:58.357475+00:00 | 2022-09-08T04:44:48.985099+00:00 | 1,101 | false | class Solution {\npublic:\n //\n //Time complexity is O(n2) as we are using a visited array, otherwise exponential 6^n\n \n //we create a map of snakes and ladders squares where key is the square where the snake/ladder starts and value is the square where that snake/ladder ends\n \n \n // at each s... | 4 | 0 | ['Breadth-First Search', 'C'] | 0 |
snakes-and-ladders | C++ solution Easy and Efficient | c-solution-easy-and-efficient-by-baibhav-hr1j | \nclass Solution {\npublic:\n int snakesAndLadders(vector<vector<int>>& board) {\n int n=board.size();\n vector<vector<int>> vis(n,vector<int>( | baibhavsaikia | NORMAL | 2022-08-28T20:47:12.670017+00:00 | 2022-08-28T20:47:12.670056+00:00 | 412 | false | ```\nclass Solution {\npublic:\n int snakesAndLadders(vector<vector<int>>& board) {\n int n=board.size();\n vector<vector<int>> vis(n,vector<int>(n,0));\n queue<int> q;\n q.push(1);\n vis[n-1][0]=1;\n int c=0;\n while(!q.empty()){\n int size=q.size();\n ... | 4 | 1 | ['Breadth-First Search', 'C'] | 0 |
snakes-and-ladders | easy to understand bfs c++ clean code tricky steps commented | easy-to-understand-bfs-c-clean-code-tric-4r1c | Tips :\nTry to think for simple numbered grid (not boustrophedonical as here) \nthen modify the code\n\nclass Solution {\npublic:\n int snakesAndLadders(vect | user5536c | NORMAL | 2021-02-23T15:21:30.637937+00:00 | 2021-03-01T10:19:48.270723+00:00 | 221 | false | Tips :\nTry to think for simple numbered grid (not boustrophedonical as here) \nthen modify the code\n```\nclass Solution {\npublic:\n int snakesAndLadders(vector<vector<int>>& board) {\n int n = board.size(), d = n*n, moves = 0;\n queue<int> q;\n q.push(1);\n vector<bool> vis(d+1,0);\n ... | 4 | 0 | [] | 0 |
snakes-and-ladders | Java solution with descriptive variables for easy understanding | java-solution-with-descriptive-variables-tyc3 | Same solution as given by LC but some descriptive variables for easy understanding\n\nclass Solution {\n public int snakesAndLadders(int[][] board) {\n | CodeMyWayOut | NORMAL | 2020-05-31T15:44:55.975194+00:00 | 2020-05-31T15:46:01.878506+00:00 | 650 | false | Same solution as given by LC but some descriptive variables for easy understanding\n```\nclass Solution {\n public int snakesAndLadders(int[][] board) {\n if (board == null || board.length == 0)\n return -1;\n \n int n = board.length;\n \n Map<Integer, Integer> squareDis... | 4 | 0 | ['Breadth-First Search', 'Java'] | 0 |
snakes-and-ladders | C# | Adapted Solution for Readability | c-adapted-solution-for-readability-by-ma-6n1e | I know a lot of us were having a tough time understanding the solution, so I tried adapting it to (hopefully) make it more readable. \n\npublic class Solution { | mattjordan0887 | NORMAL | 2020-05-22T20:56:59.610810+00:00 | 2020-05-22T20:56:59.610844+00:00 | 147 | false | I know a lot of us were having a tough time understanding the solution, so I tried adapting it to (hopefully) make it more readable. \n```\npublic class Solution {\n public int SnakesAndLadders(int[][] board) \n {\n int n = board.Length;\n int destination = n*n;\n \n Dictionary<int, in... | 4 | 0 | [] | 0 |
snakes-and-ladders | Python BFS 1D Array | python-bfs-1d-array-by-xbox360555-no6m | BFS\n\n# BFS\nclass Solution:\n def snakesAndLadders(self, board):\n """\n :type board: List[List[int]]\n :rtype: int\n """\n | xbox360555 | NORMAL | 2018-09-23T04:04:42.799684+00:00 | 2018-09-27T01:09:45.836957+00:00 | 838 | false | # BFS\n```\n# BFS\nclass Solution:\n def snakesAndLadders(self, board):\n """\n :type board: List[List[int]]\n :rtype: int\n """\n N = len(board)\n visited = [False] * (N * N)\n a = []\n s = -1\n \n # Translate the bo... | 4 | 0 | [] | 0 |
snakes-and-ladders | Simple BFS.(Java) | simple-bfsjava-by-poorvank-2hel | ``` public class SnakeAndLadders { private class Cell { private int id; private int minMovesFromStart; Cell(int id) { this.id = id; } | poorvank | NORMAL | 2018-09-23T03:14:28.833743+00:00 | 2018-09-23T03:15:17.088131+00:00 | 1,167 | false | ```
public class SnakeAndLadders {
private class Cell {
private int id;
private int minMovesFromStart;
Cell(int id) {
this.id = id;
}
Cell() {
}
}
public int snakesAndLadders(int[][] board) {
Queue<Cell> queue = new LinkedList<>();
... | 4 | 1 | [] | 1 |
snakes-and-ladders | Python3 Solution - Simplify the board and win | python3-solution-simplify-the-board-and-ijbag | Approach - Preprocessing the boardThe basic idea is to approach it as a basic BFS problem, since we want to find the minimum number of moves to get to the end. | kobyl125 | NORMAL | 2025-01-23T19:40:09.171885+00:00 | 2025-01-23T19:40:09.171885+00:00 | 331 | false | # Approach - Preprocessing the board
The basic idea is to approach it as a basic BFS problem, since we want to find the minimum number of moves to get to the end. One big simplification is turning the 2d board into a 1d list, since we notice that both snakes and ladders are simply shortcuts to a different square.
T... | 3 | 0 | ['Python3'] | 1 |
snakes-and-ladders | KOTLIN and JAVA solution | kotlin-and-java-solution-by-anlk-1w5h | \u2618\uFE0F\u2618\uFE0F\u2618\uFE0F If this solution was helpful, please consider upvoting! \u2705\n\n# Intuition\nThe problem can be modeled as finding the sh | anlk | NORMAL | 2024-11-14T20:44:17.593675+00:00 | 2024-11-14T20:44:17.593704+00:00 | 163 | false | \u2618\uFE0F\u2618\uFE0F\u2618\uFE0F If this solution was helpful, please consider upvoting! \u2705\n\n# Intuition\nThe problem can be modeled as finding the shortest path in an unweighted graph:\n\n- Each square on the board is a node.\n- A dice roll determines the edges (connections between nodes).\n- Snakes and ladd... | 3 | 0 | ['Array', 'Breadth-First Search', 'Matrix', 'Java', 'Kotlin'] | 0 |
snakes-and-ladders | ✅99% BEATS | BFS | JAVA | EXPLAINED🔥🔥🔥 | 99-beats-bfs-java-explained-by-adnannsha-mkcl | Initial Setup:\nWe calculate the destination which is the last cell on the board (i.e., n * n).\nWe create a visited array to track which cells we\'ve already v | AdnanNShaikh | NORMAL | 2024-09-08T16:17:00.332056+00:00 | 2024-09-08T16:17:00.332094+00:00 | 379 | false | **Initial Setup:**\nWe calculate the destination which is the last cell on the board (i.e., n * n).\nWe create a visited array to track which cells we\'ve already visited to avoid cycles and redundant checks.\n\n**BFS Initialization:**\nBFS starts from cell 1, and the queue is initialized with this starting cell.\nWe k... | 3 | 0 | ['Java'] | 0 |
snakes-and-ladders | Short and Easy || BFS || HashSet and Queue | short-and-easy-bfs-hashset-and-queue-by-fx5pq | \nclass Solution {\n public int snakesAndLadders(int[][] board) {\n int n = board.length;\n Queue<int[]> queue = new LinkedList<>();\n q | spats7 | NORMAL | 2023-10-12T02:52:57.830175+00:00 | 2023-10-12T02:52:57.830198+00:00 | 500 | false | ```\nclass Solution {\n public int snakesAndLadders(int[][] board) {\n int n = board.length;\n Queue<int[]> queue = new LinkedList<>();\n queue.add(new int[]{1,0});\n Set<Integer> visited = new HashSet<>();\n visited.add(1);\n while(!queue.isEmpty()){\n \n ... | 3 | 0 | ['Breadth-First Search', 'Queue', 'Ordered Set', 'Java'] | 0 |
snakes-and-ladders | Why not dijkstra? w/ Explanation for beginner understanding (Simple) | why-not-dijkstra-w-explanation-for-begin-w41h | Why not dijkstra?\n1. Using priority queue doesn;t make sense as we are moving in sequential order from visiting nodes with 1 distance then visiting nodes with | ankitkumarhello20 | NORMAL | 2023-02-14T11:27:07.991276+00:00 | 2023-06-26T17:12:34.681818+00:00 | 569 | false | Why not dijkstra?\n1. Using priority queue doesn;t make sense as we are moving in sequential order from visiting nodes with 1 distance then visiting nodes with 2 distance and so on.\n2. Then if(dist[dest]>dist[curr]+1) becomes useless as by visiting the node first time has the shortest path , so this condition won\'... | 3 | 0 | ['Breadth-First Search'] | 0 |
snakes-and-ladders | ✅Accepted | | ✅Easy solution || ✅Short & Simple || ✅Best Method | accepted-easy-solution-short-simple-best-mw71 | \n# Code\n\nclass Solution {\npublic:\n int snakesAndLadders(vector<vector<int>>& board) {\n int n=board.size();\n queue<int> q;\n vecto | sanjaydwk8 | NORMAL | 2023-01-26T04:15:46.462143+00:00 | 2023-01-26T04:15:46.462175+00:00 | 78 | false | \n# Code\n```\nclass Solution {\npublic:\n int snakesAndLadders(vector<vector<int>>& board) {\n int n=board.size();\n queue<int> q;\n vector<bool> v(n*n+1, false);\n vector<int> nums;\n nums.push_back(0);\n int c=0;\n for(int i=n-1;i>=0;i--)\n {\n if... | 3 | 0 | ['C++'] | 1 |
snakes-and-ladders | Why not simplest BFS template | See this | why-not-simplest-bfs-template-see-this-b-c324 | YouTube Link : https://www.youtube.com/watch?v=26IT3FYm5h8\n\nclass Solution {\npublic:\n int n;\n \n pair<int, int> getCoord(int s) {\n int row | mazhar_mik | NORMAL | 2023-01-24T14:38:09.802893+00:00 | 2023-01-24T14:38:09.802925+00:00 | 158 | false | YouTube Link : https://www.youtube.com/watch?v=26IT3FYm5h8\n```\nclass Solution {\npublic:\n int n;\n \n pair<int, int> getCoord(int s) {\n int row = n-1-(s-1)/n;\n \n int col = (s-1)%n;\n \n if((n%2==1 && row%2==1)||(n%2==0 && row%2==0))\n col = n-1-col;\n ... | 3 | 0 | [] | 0 |
snakes-and-ladders | C++ || BFS || Easy & Faster than 97% 🔥 | c-bfs-easy-faster-than-97-by-me__nik-bd6e | Approach\n Describe your approach to solving the problem. \n1. store ladders and snakes in map through board(given array).\n2. Make a visited bool array and pus | me__nik | NORMAL | 2023-01-24T06:45:40.823589+00:00 | 2023-01-24T07:40:13.693165+00:00 | 1,278 | false | # Approach\n<!-- Describe your approach to solving the problem. -->\n1. store ladders and snakes in map through board(given array).\n2. Make a visited bool array and push visited values in a queue.\n3. check if ladder/snake present at current grid or not, and push max value reachable to queue.\n4. iterate over all poss... | 3 | 0 | ['Breadth-First Search', 'Queue', 'Ordered Map', 'C++'] | 1 |
snakes-and-ladders | Simple || JAVA || 101 % Working || Beginners | simple-java-101-working-beginners-by-moh-7558 | 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 | Moh-Sameer-Khan | NORMAL | 2023-01-24T06:31:20.307646+00:00 | 2023-01-24T06:31:20.307685+00:00 | 834 | 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 | ['Java'] | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.