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
symmetric-tree
👏🏻 Python | DFS - 公瑾™
python-dfs-gong-jin-tm-by-yuzhoujr-vwar
101. Symmetric Tree\n\n\u8FD9\u9053\u9898\u5177\u4F53\u7684Recursion Rule\u4E0D\u662F\u4F20\u9012Root\u672C\u8EAB\uFF0C\u800C\u662F\u5BF9\u4E24\u4E2A\u5B50\u5B
yuzhoujr
NORMAL
2018-10-19T21:18:33.051304+00:00
2018-10-19T21:18:33.051368+00:00
915
false
### 101. Symmetric Tree\n\n\u8FD9\u9053\u9898\u5177\u4F53\u7684Recursion Rule\u4E0D\u662F\u4F20\u9012Root\u672C\u8EAB\uFF0C\u800C\u662F\u5BF9\u4E24\u4E2A\u5B50\u5B69\u5B50\u7684\u6BD4\u8F83\uFF0C\u6240\u4EE5Helper\u7684\u53C2\u6570\u5B9A\u4E49\u4E3A`root.left` \u548C `root.right`. \u7136\u540E\u6839\u636E\u9898\u76EE\...
9
1
[]
1
symmetric-tree
My 16ms C++ solution
my-16ms-c-solution-by-skillness-8pyc
\n bool DFS(TreeNode *left,TreeNode *right)\n {\n if(left == NULL || right == NULL)\n return left == right;\n return (left->val =
skillness
NORMAL
2014-12-02T13:34:43+00:00
2014-12-02T13:34:43+00:00
1,135
false
\n bool DFS(TreeNode *left,TreeNode *right)\n {\n if(left == NULL || right == NULL)\n return left == right;\n return (left->val == right->val)&DFS(left->right,right->left)&DFS(left->left,right->right);\n }\n bool isSymmetric(TreeNode *root) {\n if(root == NULL)\n ...
9
0
[]
1
symmetric-tree
Two Simple Accepted Java solutions. Recursion and Iteration.
two-simple-accepted-java-solutions-recur-b3bu
The idea is simple. Traverse both on left an right branches of the root symmetricaly and check if the values are equal.\n\n\nRecursion.\n\n public boolean is
pavel-shlyk
NORMAL
2015-01-18T17:24:56+00:00
2015-01-18T17:24:56+00:00
1,288
false
The idea is simple. Traverse both on left an right branches of the root symmetricaly and check if the values are equal.\n\n\nRecursion.\n\n public boolean isSymmetric(TreeNode root) {\n return root == null ? true : symmetric(root.left, root.right);\n }\n\t\n\tpublic boolean symmetric(TreeNode left, TreeNod...
9
0
[]
2
symmetric-tree
[Recusive solution for symmetric tree]: is it an optimal solution to use inorderTraversal?
recusive-solution-for-symmetric-tree-is-c2z7l
The approach I have is:\n1. get two vectors which saves both left and right sides of the root in inorderTraversal format.\n2. compare the vectors to see if they
wshaoxuan
NORMAL
2013-11-12T23:41:48+00:00
2013-11-12T23:41:48+00:00
9,297
false
The approach I have is:\n1. get two vectors which saves both left and right sides of the root in inorderTraversal format.\n2. compare the vectors to see if they are symmetric.\nIt needs extra O(2n) space, not sure if this is an accepted solution. Or is there any better to solve this problem recursively.\n\n /*recusi...
9
2
[]
5
symmetric-tree
7 lines c++ solution
7-lines-c-solution-by-wuhaibing-yzfj
/\nThe key is to traverse the left subtree with order root -> left -> right, \nand the right subtree with order root -> right-> left\n/\n\n\n bool isSymmetri
wuhaibing
NORMAL
2015-07-13T03:38:10+00:00
2015-07-13T03:38:10+00:00
1,314
false
/*\nThe key is to traverse the left subtree with order root -> left -> right, \nand the right subtree with order root -> right-> left\n*/\n\n\n bool isSymmetric(TreeNode* root) {\n if (!root) return true;\n return isSymmetric_helper(root->left, root->right);\n }\n bool isSymmetric_helper(TreeNode...
9
0
[]
1
symmetric-tree
✅BEATS 100% | DFS | JAVA | EXPLAINED🔥🔥🔥
beats-100-dfs-java-explained-by-adnannsh-lk5d
Approach:\n\nEmploys a recursive approach to compare the left and right subtrees of the root node.\nThe isSameTree function compares two nodes for equality and
AdnanNShaikh
NORMAL
2024-08-31T17:56:09.254533+00:00
2024-08-31T17:56:09.254584+00:00
1,510
false
**Approach:**\n\nEmploys a recursive approach to compare the left and right subtrees of the root node.\nThe isSameTree function compares two nodes for equality and recursively compares their corresponding subtrees.\nThe isSymmetric function calls isSameTree with the root node as both arguments, effectively comparing th...
8
0
['Java']
0
symmetric-tree
Nice and clear 🟩🟩🟩 beats 89.91%
nice-and-clear-beats-8991-by-teklumt-7oe7
\n\n# Approach\n Describe your approach to solving the problem. \nNice and clear \uD83D\uDFE9\uD83D\uDFE9\uD83D\uDFE9 beats 89.91% \n\n# Complexity\n- Time comp
teklumt
NORMAL
2024-01-14T20:47:18.211885+00:00
2024-01-14T20:47:18.211943+00:00
2,580
false
\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nNice and clear \uD83D\uDFE9\uD83D\uDFE9\uD83D\uDFE9 beats 89.91% \n\n# Complexity\n- Time complexity:O(N)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(H)\n- where \'H\' is the height of the tree\n<!-- Add your spa...
8
0
['Python', 'Python3']
3
symmetric-tree
c++ solution
c-solution-by-loverdrama699-4s3f
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
loverdrama699
NORMAL
2023-03-13T11:31:27.762117+00:00
2023-03-13T11:31:27.762144+00:00
1,239
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)$$ --...
8
0
['C++']
2
symmetric-tree
C# Iterative DFS
c-iterative-dfs-by-ilya-a-f-5kuf
\npublic class Solution\n{\n public bool IsSymmetric(TreeNode root)\n {\n if (root == null)\n {\n return true;\n }\n\n
ilya-a-f
NORMAL
2023-03-13T10:38:18.947843+00:00
2023-03-13T11:12:35.377034+00:00
1,712
false
```\npublic class Solution\n{\n public bool IsSymmetric(TreeNode root)\n {\n if (root == null)\n {\n return true;\n }\n\n var stack = new Stack<(TreeNode, TreeNode)>();\n stack.Push((root.left, root.right));\n\n while (stack.Any())\n {\n switc...
8
0
['C#']
1
symmetric-tree
Easy C++ Solution|| DFS || Beats 100% ✔✔ || Explanation ✔✔
easy-c-solution-dfs-beats-100-explanatio-gh8c
Approach\n Describe your approach to solving the problem. \n1. Do preorder traversal in the left subtree (node-left-right) and preorder traversal in reverse man
mamatva004
NORMAL
2023-02-17T06:17:10.214001+00:00
2023-03-13T04:42:33.321697+00:00
1,622
false
# Approach\n<!-- Describe your approach to solving the problem. -->\n1. Do preorder traversal in the left subtree (node-left-right) and preorder traversal in reverse manner (node-right-left) in the right subtree. \n2. At any point, if we find any dissimilarity then the tree is not symmetric, otherwise it is symmetric.\...
8
0
['C++']
0
symmetric-tree
Tree || 100% Beat || 0ms runtime || Easy-to-understand
tree-100-beat-0ms-runtime-easy-to-unders-i9qd
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
mridulxtiwari
NORMAL
2023-01-16T14:32:26.810695+00:00
2023-01-16T14:32:26.810728+00:00
1,306
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)$$ --...
8
0
['C++']
0
symmetric-tree
Recursive and iterative JS versions
recursive-and-iterative-js-versions-by-r-4yp1
Recursive:\n\nvar isSymmetric = function(root) {\n/**\n * Compares two TreeNode\'s\n * @param {TreeNode} root1\n * @param {TreeNode} root2\n * @return {boolean}
rinat_a
NORMAL
2021-09-06T19:06:27.031358+00:00
2021-09-07T07:45:58.279405+00:00
765
false
Recursive:\n```\nvar isSymmetric = function(root) {\n/**\n * Compares two TreeNode\'s\n * @param {TreeNode} root1\n * @param {TreeNode} root2\n * @return {boolean}\n */\n function isEqual(root1, root2) {\n if (!root1 && !root2) return true;\n if (!root1 || !root2) return false;\n return root1.va...
8
0
['JavaScript']
2
symmetric-tree
0 ms, faster than 100.00% of Java online submissions
0-ms-faster-than-10000-of-java-online-su-9gq1
Runtime: 0 ms, faster than 100.00% of Java online submissions for Symmetric Tree.\nMemory Usage: 37.4 MB, less than 74.15% of Java online submissions for Symmet
aroraharsh010
NORMAL
2020-05-20T20:09:00.026813+00:00
2020-05-21T08:29:33.095790+00:00
483
false
Runtime: 0 ms, faster than 100.00% of Java online submissions for Symmetric Tree.\nMemory Usage: 37.4 MB, less than 74.15% of Java online submissions for Symmetric Tree.\n```\nclass Solution {\n public boolean isSymmetric(TreeNode root) {\n return root==null || traverse(root.left,root.right);\n }\n priv...
8
1
['Recursion', 'Java']
0
symmetric-tree
Share 3 methods to solve this problem (Java)
share-3-methods-to-solve-this-problem-ja-nuap
First.\nWe can define a binary tree by mid-order and post-order or pre-order and mid-order, the mirror tree is same to the origin tree. So we can check these tw
tovenja
NORMAL
2015-03-22T09:48:14+00:00
2015-03-22T09:48:14+00:00
876
false
First.\nWe can define a binary tree by mid-order and post-order or pre-order and mid-order, the mirror tree is same to the origin tree. So we can check these two trees' mid-order and post-order are all same?\n\n public boolean isSymmetric(TreeNode root) {\n if (root==null)\n return true;\n ...
8
0
['Java']
1
moving-stones-until-consecutive-ii
[Java/C++/Python] Sliding Window
javacpython-sliding-window-by-lee215-7anh
Lower Bound\nAs I mentioned in my video last week,\nin case of n stones, \nwe need to find a consecutive n positions and move the stones in.\n\nThis idea led th
lee215
NORMAL
2019-05-05T04:11:08.235416+00:00
2020-03-12T15:17:15.969095+00:00
16,742
false
## Lower Bound\nAs I mentioned in my video last week,\nin case of `n` stones, \nwe need to find a consecutive `n` positions and move the stones in.\n\nThis idea led the solution with sliding windows.\n\nSlide a window of size `N`, and find how many stones are already in this window.\nWe want moves other stones into thi...
179
8
[]
38
moving-stones-until-consecutive-ii
c++ with picture
c-with-picture-by-xiongqiangcs-9m14
the max move\n\nintuition we need the max move A[n-1]-A[0]-n+1\n\nuse the case 1 2 99 100\n\n\n\n\nbut the endpoint stone exist an hole, if you move the endpoi
xiongqiangcs
NORMAL
2019-05-09T10:29:20.602394+00:00
2019-05-10T08:07:57.823176+00:00
6,086
false
## the max move\n\n**intuition we need the max move** `A[n-1]-A[0]-n+1`\n\nuse the case `1 2 99 100`\n\n![image](https://assets.leetcode.com/users/xiongqiangcs/image_1557397438.png)\n\n\n**but the endpoint stone exist an hole**, if you move the endpoint stone firstly, the hole will disappear\n\nuse the case `1 100 102...
125
1
[]
14
moving-stones-until-consecutive-ii
C++ O(nlogn) with detailed explanation
c-onlogn-with-detailed-explanation-by-hk-ibjh
Sort it first.\n1. How to get the minimum steps?\n\tWe can transfer this question into a problem like:\n\tFind the longest subsequence of a sorted array with ma
hkreporter
NORMAL
2019-05-05T04:32:47.306303+00:00
2019-05-06T19:57:07.859762+00:00
3,964
false
Sort it first.\n1. How to get the minimum steps?\n\tWe can transfer this question into a problem like:\n\tFind the longest subsequence of a sorted array with max difference==n-1;\n\tFor example, [1, 4, 5, 6, 10], the longest subsequence is 4,5,6, we just need to move 1 and 10 close to 4, 5, 6, so we just need n - len: ...
39
2
[]
11
moving-stones-until-consecutive-ii
C++ solution | Sliding window for minimum moves
c-solution-sliding-window-for-minimum-mo-pmmf
First, sort the given stones array.\n1. To find minimum moves, we approach the problem by checking each window which has a size not greater than stones.size().
shivamxarora
NORMAL
2020-03-29T20:33:47.651301+00:00
2020-06-12T07:04:04.003635+00:00
2,466
false
First, **sort** the given stones array.\n1. To find **minimum** moves, we approach the problem by checking each window which has a size not greater than **stones.size()**. The intitution is that in a window which has size less than or equal to the number of stones, we can always get the unoccupied spaces and accordingl...
16
0
['C', 'Sliding Window']
2
moving-stones-until-consecutive-ii
Python solution w/ comments
python-solution-w-comments-by-haoyangfan-so40
py\nclass Solution:\n def numMovesStonesII(self, stones: List[int]) -> List[int]:\n A = sorted(stones)\n n = len(stones)\n \n # e
haoyangfan
NORMAL
2019-07-28T18:49:21.115767+00:00
2019-07-28T18:49:21.115803+00:00
1,460
false
```py\nclass Solution:\n def numMovesStonesII(self, stones: List[int]) -> List[int]:\n A = sorted(stones)\n n = len(stones)\n \n # either keep moving the stone at right endpoint to the left interval between A[0] ... A[n - 2]\n # basically each empty spot can consume 1 move, so tota...
15
0
[]
3
moving-stones-until-consecutive-ii
This should by no means be a Medium question
this-should-by-no-means-be-a-medium-ques-6f1t
\tclass Solution {\n\tpublic:\n\t\tvector numMovesStonesII(vector& stones) {\n\t\t\tsort(stones.begin(),stones.end());\n\t\t\tint n=stones.size();\n\t\t\tint MA
jasperjoe
NORMAL
2019-12-28T13:23:33.719636+00:00
2019-12-28T13:23:33.719669+00:00
2,021
false
\tclass Solution {\n\tpublic:\n\t\tvector<int> numMovesStonesII(vector<int>& stones) {\n\t\t\tsort(stones.begin(),stones.end());\n\t\t\tint n=stones.size();\n\t\t\tint MAX=0;\n\t\t\tint MIN=INT_MAX;\n\t\t\tint a=stones.back()-stones[1]+1-(n-1);\n\t\t\tint b=stones[n-2]-stones[0]+1-(n-1);\n\t\t\tint j=0;\n\t\t\tMAX=max(...
10
1
['C', 'Sliding Window', 'C++']
1
moving-stones-until-consecutive-ii
C++ Code With Easy Explanation
c-code-with-easy-explanation-by-chronovi-lxag
```\nclass Solution {\npublic:\n vector numMovesStonesII(vector& A) {\n int n = A.size(); //number of stones\n \n sort(A.begin(), A.end()
chronoviser
NORMAL
2020-06-10T15:19:18.288356+00:00
2020-06-10T15:19:18.288386+00:00
1,339
false
```\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& A) {\n int n = A.size(); //number of stones\n \n sort(A.begin(), A.end());\n \n //To find max_moves:\n //move either starting endstone, or end endstone : this consumes one Move\n //after this we cal...
9
1
[]
2
moving-stones-until-consecutive-ii
Short C++ O(nlogn) solution, 7 lines
short-c-onlogn-solution-7-lines-by-mzche-y6vp
\nvector<int> numMovesStonesII(vector<int>& s) {\n sort(s.begin(), s.end());\n int n = s.size(), gaps = s[n - 1] - s[0] + 1 - n, low = INT_MAX;\n if (s
mzchen
NORMAL
2019-05-05T06:14:06.919899+00:00
2019-05-05T06:14:06.919947+00:00
1,233
false
```\nvector<int> numMovesStonesII(vector<int>& s) {\n sort(s.begin(), s.end());\n int n = s.size(), gaps = s[n - 1] - s[0] + 1 - n, low = INT_MAX;\n if (s[1] - s[0] == gaps + 1 || s[n - 1] - s[n - 2] == gaps + 1)\n low = min(2, gaps);\n else for (int i = 0; i < n; i++) // window slides here\n ...
9
3
[]
0
moving-stones-until-consecutive-ii
Python 3 || 8 lines, sliding window w/ bin search || T/S: 66% / 57%
python-3-8-lines-sliding-window-w-bin-se-8rcd
Pretty much what everyone else has, but for what it\'s worth, it does use a bin search to locate the windows.\n\nclass Solution:\n def numMovesStonesII(self,
Spaulding_
NORMAL
2022-11-16T16:38:17.688096+00:00
2024-05-31T21:47:47.678289+00:00
877
false
Pretty much what everyone else has, but for what it\'s worth, it does use a bin search to locate the windows.\n```\nclass Solution:\n def numMovesStonesII(self, stones: List[int]) -> List[int]:\n \n stones.sort()\n n, lo = len(stones), inf\n\n for right in range(n):\n\n left= b...
8
0
['Python']
0
moving-stones-until-consecutive-ii
Is it really Medium?
is-it-really-medium-by-ayush33-e9hy
Is it only me who feels this should be very hard or I am just a noob with coding?
ayush33
NORMAL
2022-02-27T13:13:05.786939+00:00
2022-02-27T13:13:05.786979+00:00
659
false
Is it only me who feels this should be very hard or I am just a noob with coding?
7
0
[]
1
moving-stones-until-consecutive-ii
[Python] Sliding window with detailed expalanation
python-sliding-window-with-detailed-expa-aeoc
python\nclass Solution:\n def numMovesStonesII(self, stones: list[int]) -> list[int]:\n """\n 1. For the higher bound, it is determined by eith
eroneko
NORMAL
2021-09-27T04:41:41.067924+00:00
2021-09-27T04:41:41.067968+00:00
1,156
false
```python\nclass Solution:\n def numMovesStonesII(self, stones: list[int]) -> list[int]:\n """\n 1. For the higher bound, it is determined by either moving the leftmost\n to the right side, or by moving the rightmost to the left side:\n 1.1 If moving leftmost to the right side, th...
6
0
['Sliding Window', 'Python3']
2
moving-stones-until-consecutive-ii
Python sliding window approach O(N)
python-sliding-window-approach-on-by-abh-lofx
For minimum number of moves, the final arrangement will be of the form [a, a+1, a+2, ... a+L-1] for L stones for some \'a\'. \nThe possible values of \'a\' are
abhi2iitk
NORMAL
2020-02-23T18:51:08.162011+00:00
2020-02-23T18:53:47.245875+00:00
767
false
For minimum number of moves, the final arrangement will be of the form [a, a+1, a+2, ... a+L-1] for L stones for some \'a\'. \nThe possible values of \'a\' are all the stone positions in the given input array.\nFor each possible \'a\' check how many positions (from a to a+L-1) already have stones. We need to fill in th...
5
4
[]
2
moving-stones-until-consecutive-ii
Java || Easy
java-easy-by-pankaj1417-3bv2
\n\t\tclass Solution {\n\t\t\tpublic int[] numMovesStonesII(int[] stones) {\n\t\t\t\tint n = stones.length;\n\t\t\t\t int[] ans = new int[2];\n\t\t\t\t int i =
Pankaj1417
NORMAL
2021-06-01T13:39:33.114103+00:00
2021-06-01T13:40:27.949200+00:00
865
false
\n\t\tclass Solution {\n\t\t\tpublic int[] numMovesStonesII(int[] stones) {\n\t\t\t\tint n = stones.length;\n\t\t\t\t int[] ans = new int[2];\n\t\t\t\t int i = 0, j = 0, wsize, scount, minMoves = Integer.MAX_VALUE;\n\t\t\t\tArrays.sort(stones);\n\t\t\t\t while (j < n) {\n\t\t\t\t\twsize = stones[j] - stones[i] + 1;\n\t...
4
1
['Sliding Window', 'Java']
0
moving-stones-until-consecutive-ii
Use Interval to Get Max Moves
use-interval-to-get-max-moves-by-nullpoi-4cnl
I failed to figure out the min moves... The following is an intuitive solution for max moves.\n1. Sort and get the intervals.\n2. Check the first and last inter
nullpointer01
NORMAL
2019-05-05T10:20:53.429414+00:00
2019-05-05T10:26:33.524443+00:00
592
false
I failed to figure out the min moves... The following is an intuitive solution for max moves.\n1. Sort and get the intervals.\n2. Check the first and last interval, if either is `0`, we are able to reduce every non-zero interval to zero at every smallest move (`1`). Thus, the number of moves is the sum of intervals.\n3...
3
0
[]
0
moving-stones-until-consecutive-ii
Moving Stones Until Consecutive II
moving-stones-until-consecutive-ii-by-an-x2oy
Code
Ansh1707
NORMAL
2025-03-28T16:21:10.137501+00:00
2025-03-28T16:21:10.137501+00:00
29
false
# Code ```python [] class Solution(object): def numMovesStonesII(self, stones): """ :type stones: List[int] :rtype: List[int] """ stones.sort() n = len(stones) maxMoves = max(stones[-1] - stones[1] - (n - 2), stones[-2] - stones[0] - (n - 2)) minMo...
2
0
['Array', 'Math', 'Sorting', 'Python']
0
moving-stones-until-consecutive-ii
Solution in Java
solution-in-java-by-shree_govind_jee-em0f
Intuition\nLower Bound\nAs I mentioned in my video last week,\nin case of n stones,\nwe need to find a consecutive n positions and move the stones in.\n\nThis i
Shree_Govind_Jee
NORMAL
2023-12-06T08:46:30.359179+00:00
2023-12-06T08:46:30.359207+00:00
374
false
# Intuition\n**Lower Bound**\nAs I mentioned in my video last week,\nin case of n stones,\nwe need to find a consecutive n positions and move the stones in.\n\nThis idea led the solution with sliding windows.\n\nSlide a window of size N, and find how many stones are already in this window.\nWe want moves other stones i...
2
0
['Array', 'Math', 'Two Pointers', 'Sorting', 'Java']
0
moving-stones-until-consecutive-ii
100 T and S | Commented and Explained With Examples
100-t-and-s-commented-and-explained-with-0xme
Intuition\n Describe your first thoughts on how to solve this problem. \nAt the base of this problem is a linear scan. This is because we are trying to achieve
laichbr
NORMAL
2023-07-29T13:03:47.946264+00:00
2023-07-29T13:03:47.946284+00:00
117
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nAt the base of this problem is a linear scan. This is because we are trying to achieve the pairing of minimum number of moves and maximum number of moves. As such, we are trying to sort the move value space and scan over it linearly. This...
2
0
['Python3']
0
moving-stones-until-consecutive-ii
[ C++ ] [ Sliding Window ]
c-sliding-window-by-sosuke23-9bsr
Code\n\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& stones) {\n sort(stones.begin(), stones.end());\n\n int N = stone
Sosuke23
NORMAL
2023-04-25T14:45:07.410143+00:00
2023-04-25T14:45:07.410187+00:00
935
false
# Code\n```\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& stones) {\n sort(stones.begin(), stones.end());\n\n int N = stones.size(), low = N;\n for (int i = 0, j = 0; j < N; ++j) {\n while (stones[j] - stones[i] + 1 > N) {\n ++i;\n }\...
2
0
['C++']
0
moving-stones-until-consecutive-ii
[Java] simple+clean sliding window
java-simpleclean-sliding-window-by-66bro-ufti
\nclass Solution {\n public int[] numMovesStonesII(int[] A) {\n Arrays.sort(A);\n int N=A.length;\n if(A[N-1]-A[0]+1==A.length)return ne
66brother
NORMAL
2020-10-07T22:55:36.371305+00:00
2020-10-07T22:55:36.371336+00:00
670
false
```\nclass Solution {\n public int[] numMovesStonesII(int[] A) {\n Arrays.sort(A);\n int N=A.length;\n if(A[N-1]-A[0]+1==A.length)return new int[]{0,0};\n \n int max=1+Math.max(A[N-1]-A[1]+1-N,A[N-2]-A[0]+1-N); \n int min=Integer.MAX_VALUE;\n \n \n Queu...
2
1
[]
1
moving-stones-until-consecutive-ii
Not shortest but easiest to understand solution
not-shortest-but-easiest-to-understand-s-jsvs
\nclass Solution { \n public int[] numMovesStonesII(int[] stones) {\n int max;\n Arrays.sort(stones);\n int len = stones.length;\n int
privatetrain
NORMAL
2019-06-17T06:29:26.033407+00:00
2019-06-17T06:29:26.033446+00:00
681
false
```\nclass Solution { \n public int[] numMovesStonesII(int[] stones) {\n int max;\n Arrays.sort(stones);\n int len = stones.length;\n int gaps = stones[len - 1] - stones[0] + 1 - len;\n if (stones[0] + 1 == stones[1] || stones[len - 1] == stones[len - 2] + 1) {\n max = gaps;\n ...
2
0
[]
1
moving-stones-until-consecutive-ii
Easy to understand JavaScript solution
easy-to-understand-javascript-solution-b-teq7
\nvar numMovesStonesII = function(stones) {\n stones.sort((a, b) => a - b);\n const { length: size } = stones;\n const max = Math.max(stones[size - 1]
tzuyi0817
NORMAL
2023-02-18T07:29:55.636042+00:00
2023-02-18T07:29:55.636092+00:00
73
false
```\nvar numMovesStonesII = function(stones) {\n stones.sort((a, b) => a - b);\n const { length: size } = stones;\n const max = Math.max(stones[size - 1] - stones[1] - size + 2, stones[size - 2] - stones[0] - size + 2);\n let start = 0;\n let min = size;\n\n for (let end = 1; end < size; end++) {\n ...
1
0
['JavaScript']
0
moving-stones-until-consecutive-ii
c++ | easy | fast
c-easy-fast-by-venomhighs7-jeac
\n\n# Code\n\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& A) {\n sort(A.begin(), A.end());\n int i = 0, n = A.size
venomhighs7
NORMAL
2022-11-17T04:52:18.328214+00:00
2022-11-17T04:52:18.328256+00:00
853
false
\n\n# Code\n```\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& A) {\n sort(A.begin(), A.end());\n int i = 0, n = A.size(), low = n;\n int high = max(A[n - 1] - n + 2 - A[1], A[n - 2] - A[0] - n + 2);\n for (int j = 0; j < n; ++j) {\n while (A[j] - A[i...
1
0
['C++']
0
moving-stones-until-consecutive-ii
c++ | easy | fast
c-easy-fast-by-venomhighs7-plzo
\n\n# Code\n\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& A) {\n sort(A.begin(), A.end());\n int i = 0, n = A.size
venomhighs7
NORMAL
2022-11-17T04:51:41.997741+00:00
2022-11-17T04:51:41.997773+00:00
340
false
\n\n# Code\n```\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& A) {\n sort(A.begin(), A.end());\n int i = 0, n = A.size(), low = n;\n int high = max(A[n - 1] - n + 2 - A[1], A[n - 2] - A[0] - n + 2);\n for (int j = 0; j < n; ++j) {\n while (A[j] - A[i...
1
0
['C++']
0
moving-stones-until-consecutive-ii
💯EASIEST || C++ || SLIDING WINDOW
easiest-c-sliding-window-by-maheshwari__-chrg
\n\nDo upvote if you like it!\n\n\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& stones) {\n sort(begin(stones), end(stones));
maheshwari__apoorv
NORMAL
2022-09-11T13:14:33.349973+00:00
2022-09-11T13:14:33.350017+00:00
503
false
\n\n**Do upvote if you like it!**\n\n```\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& stones) {\n sort(begin(stones), end(stones)); \n int n = size(stones), ii = 0, low = INT_MAX; \n int high = max(stones[n-2] - stones[0], stones[n-1] - stones[1]) - (n - 2); \n \...
1
0
['C++']
0
moving-stones-until-consecutive-ii
easy sliding window using binary search
easy-sliding-window-using-binary-search-7q157
\nFor the max step just skip the first gap or last gap. detail https://leetcode.com/problems/moving-stones-until-consecutive-ii/discuss/289357/c%2B%2B-with-pict
th160887
NORMAL
2021-08-09T06:41:41.237409+00:00
2021-08-09T06:41:41.237455+00:00
322
false
\nFor the max step just skip the first gap or last gap. detail https://leetcode.com/problems/moving-stones-until-consecutive-ii/discuss/289357/c%2B%2B-with-picture\nFor the min step, just do a sliding window and try to move everyone inside the window. result is, window with minimum movement. (one edge case)\n\n\n````\n...
1
0
[]
0
moving-stones-until-consecutive-ii
(C++) 1040. Moving Stones Until Consecutive II
c-1040-moving-stones-until-consecutive-i-7b1e
\n\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& stones) {\n sort(begin(stones), end(stones)); \n int n = size(stones)
qeetcode
NORMAL
2021-06-24T17:03:34.574866+00:00
2021-06-24T17:03:34.574909+00:00
559
false
\n```\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& stones) {\n sort(begin(stones), end(stones)); \n int n = size(stones), ii = 0, low = INT_MAX, high = max(stones[n-2] - stones[0], stones[n-1] - stones[1]) - (n - 2); \n \n for (int i = 0; i < n; ++i) {\n ...
1
0
['C']
1
moving-stones-until-consecutive-ii
C++ short solution
c-short-solution-by-guccigang-iuns
Run-time is O(NlogN), space is O(1). \n\n\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& stones) {\n std::sort(stones.begin(),
guccigang
NORMAL
2021-02-03T22:30:42.656556+00:00
2021-02-03T22:30:42.656591+00:00
519
false
Run-time is `O(NlogN)`, space is `O(1)`. \n\n```\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& stones) {\n std::sort(stones.begin(), stones.end());\n int size{(int)stones.size()}, maxSum{0};\n for(int i{1}; i < size; ++i) maxSum += stones[i]-stones[i-1]-1;\n maxSu...
1
0
[]
0
moving-stones-until-consecutive-ii
Golang solution with explanation, not good enough
golang-solution-with-explanation-not-goo-t1kd
go\nfunc numMovesStonesII(stones []int) []int {\n\tsort.Ints(stones)\n\t// calc all gaps\n\tgap := make([]int, 0)\n\tfor i := 1; i < len(stones); i++ {\n\t\tdif
tjucoder
NORMAL
2020-07-26T06:52:53.124361+00:00
2020-07-26T07:02:57.406237+00:00
169
false
```go\nfunc numMovesStonesII(stones []int) []int {\n\tsort.Ints(stones)\n\t// calc all gaps\n\tgap := make([]int, 0)\n\tfor i := 1; i < len(stones); i++ {\n\t\tdiff := stones[i] - stones[i-1]\n\t\tif diff > 1 {\n\t\t\tgap = append(gap, diff-1)\n\t\t}\n\t}\n\t// calc max here\n\t// each move, we will lost one gap\n\t// ...
1
0
['Go']
0
moving-stones-until-consecutive-ii
C# beat 100%
c-beat-100-by-wwjuan-ecn5
\npublic class Solution {\n public int[] NumMovesStonesII(int[] stones) {\n Array.Sort(stones);\n \n int i = 0, n = stones.Length, low =
wwjuan
NORMAL
2020-03-03T19:50:10.364386+00:00
2020-03-03T19:50:10.364431+00:00
182
false
```\npublic class Solution {\n public int[] NumMovesStonesII(int[] stones) {\n Array.Sort(stones);\n \n int i = 0, n = stones.Length, low = n;\n int high = Math.Max(stones[n-1] - n + 2 - stones[1], stones[n-2] - stones[0] - n + 2);\n \n for(int j = 0; j<n; j++){\n ...
1
0
[]
0
moving-stones-until-consecutive-ii
Go Solution with Detailed Explanation
go-solution-with-detailed-explanation-by-v2wj
For more golang solution, please check: https://github.com/yinfirefire/LeetCode-GoSol\ngo\nfunc numMovesStonesII(stones []int) []int {\n\tsort.Ints(stones)\n\t/
shuoyan
NORMAL
2019-12-18T02:26:08.763628+00:00
2019-12-18T02:26:08.763684+00:00
374
false
For more golang solution, please check: https://github.com/yinfirefire/LeetCode-GoSol\n```go\nfunc numMovesStonesII(stones []int) []int {\n\tsort.Ints(stones)\n\t// Upper bound:\n\t// 1, move the first stone A[0] to A[n-1]-n+1\n\t// the total number between new left bound and A[1] is the steps to take\n\t// A[n-1]-n+1-...
1
0
[]
0
moving-stones-until-consecutive-ii
C++ slide window
c-slide-window-by-sanzenin_aria-3tbi
```\nclass Solution {\npublic:\n vector numMovesStonesII(vector& stones) {\n sort(stones.begin(), stones.end());\n return { minMove(stones), maxMove
sanzenin_aria
NORMAL
2019-06-16T17:19:36.454563+00:00
2019-06-16T17:19:36.454617+00:00
496
false
```\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& stones) {\n sort(stones.begin(), stones.end());\n return { minMove(stones), maxMove(stones) };\n }\n\n int maxMove(vector<int>& v) {\n const int n = v.size();\n int left = v[1] - v[0] - 1;\n int right = v[n - 1] - ...
1
0
[]
1
moving-stones-until-consecutive-ii
C++ super easy and short 9-line solution, beats 100% time and 100% space!
c-super-easy-and-short-9-line-solution-b-dnbm
```\n\tvector numMovesStonesII(vector& stones) {\n int mx=INT_MAX, ct=0, size=stones.size(), pre=0;\n sort(stones.begin(), stones.end());\n
michaelz
NORMAL
2019-05-08T05:55:43.666380+00:00
2019-05-08T05:55:43.666447+00:00
720
false
```\n\tvector<int> numMovesStonesII(vector<int>& stones) {\n int mx=INT_MAX, ct=0, size=stones.size(), pre=0;\n sort(stones.begin(), stones.end());\n for(int i=0;i<stones.size();i++) {\n while(stones[i]-stones[pre]>size-1) pre++;\n ct=max(ct, i-pre+1);\n }\n mx=m...
1
1
[]
3
moving-stones-until-consecutive-ii
Python3: 84 ms
python3-84-ms-by-kzhang14-1qtr
\nclass Solution:\n def numMovesStonesII(self, stones: List[int]) -> List[int]:\n stones.sort()\n ma=max(stones[-1]-stones[1]-len(stones)+2,sto
kzhang14
NORMAL
2019-05-05T18:13:30.008262+00:00
2019-05-05T18:16:23.228979+00:00
348
false
```\nclass Solution:\n def numMovesStonesII(self, stones: List[int]) -> List[int]:\n stones.sort()\n ma=max(stones[-1]-stones[1]-len(stones)+2,stones[-2]-stones[0]-len(stones)+2)\n mi=0\n l=len(stones)\n for i in range(l-1):\n if stones[i]<=stones[-1]-l+1:\n ...
1
1
[]
0
moving-stones-until-consecutive-ii
Crude and undecorated solution
crude-and-undecorated-solution-by-quadpi-wga7
This is a direct dump of my thinking process ...\n To make many moves as possible, we form a "blob" of numbers and have the "blob" crawl to the other end. With
quadpixels
NORMAL
2019-05-05T04:43:14.613971+00:00
2019-05-05T04:45:08.952760+00:00
466
false
This is a direct dump of my thinking process ...\n* To make many moves as possible, we form a "blob" of numbers and have the "blob" crawl to the other end. With this approach the answer will be related to the total width of the gaps;\n * However, if both endpoints are "lonely" (meaning they have no neighbors), th...
1
1
[]
1
moving-stones-until-consecutive-ii
Python3 solution O(NlogN) with explaination
python3-solution-onlogn-with-explainatio-bdju
\nclass Solution:\n def numMovesStonesII(self, stones: List[int]) -> List[int]:\n stones.sort()\n minM = float(\'inf\')\n for i in range
davyjing
NORMAL
2019-05-05T04:06:27.787236+00:00
2019-05-05T04:48:37.094377+00:00
550
false
```\nclass Solution:\n def numMovesStonesII(self, stones: List[int]) -> List[int]:\n stones.sort()\n minM = float(\'inf\')\n for i in range(1,len(stones)-1):\n loc = bisect.bisect_left(stones, stones[i]+len(stones)-1, lo=0, hi=len(stones)-1)\n if stones[loc] == stones[i]+le...
1
1
[]
0
moving-stones-until-consecutive-ii
scala sliding window
scala-sliding-window-by-vititov-50a6
null
vititov
NORMAL
2025-02-26T21:17:03.163454+00:00
2025-02-26T21:17:03.163454+00:00
4
false
```scala [] object Solution { def numMovesStonesII(stones: Array[Int]): Array[Int] = { lazy val sorted = stones.sorted lazy val delta = (stones.length - List(0,1).map{i => sorted(sorted.length-2+i)-sorted(i)-1} .min - 2) max 0 lazy val mn = sorted.indices.foldLeft(0){case (lo,hi) => if(sorted(...
0
0
['Two Pointers', 'Sliding Window', 'Scala']
0
moving-stones-until-consecutive-ii
Sort and Binary Search O(nlgn)
sort-and-binary-search-onlgn-by-lilongxu-a1mh
IntuitionSort and analyze.Approach Sort the stones. To obtain the max moves, we choose the endpoint that has a smaller gap with its (sole) neighbour stone, in o
lilongxue
NORMAL
2025-02-16T02:20:59.271364+00:00
2025-02-16T02:20:59.271364+00:00
6
false
# Intuition Sort and analyze. # Approach 1. Sort the stones. 2. To obtain the max moves, we choose the endpoint that has a smaller gap with its (sole) neighbour stone, in order to diminish the least space. The max moves = total gaps - min(leftmost gap, rightmost gap). 3. To obtain the min moves, we need to binary searc...
0
0
['JavaScript']
0
moving-stones-until-consecutive-ii
I have no idea how I solved this
i-have-no-idea-how-i-solved-this-by-bori-s4g5
Code\npython3 []\nclass Solution:\n def numMovesStonesII(self, a: List[int]) -> List[int]:\n n = len(a)\n a.sort()\n \n maxi = 1
boriswilliams
NORMAL
2024-09-26T19:29:31.215477+00:00
2024-09-26T19:30:55.489873+00:00
53
false
# Code\n```python3 []\nclass Solution:\n def numMovesStonesII(self, a: List[int]) -> List[int]:\n n = len(a)\n a.sort()\n \n maxi = 1 - min(a[1] - a[0], a[-1] - a[-2])\n for i in range(1, n):\n maxi += a[i] - a[i-1] - 1\n \n mini = sys.maxsize\n j = ...
0
0
['Python3']
0
moving-stones-until-consecutive-ii
[Accepted] Swift
accepted-swift-by-vasilisiniak-waps
\nclass Solution {\n func numMovesStonesII(_ stones: [Int]) -> [Int] {\n\n guard stones.count > 2 else { return [0, 0] }\n \n var st = s
vasilisiniak
NORMAL
2024-06-28T16:12:10.743612+00:00
2024-06-28T16:12:10.743667+00:00
9
false
```\nclass Solution {\n func numMovesStonesII(_ stones: [Int]) -> [Int] {\n\n guard stones.count > 2 else { return [0, 0] }\n \n var st = stones.sorted()\n\n let ma = st[st.count - 1] - st[0] - min(st[1] - st[0], st[st.count - 1] - st[st.count - 2]) + 2 - st.count\n \n let m...
0
0
['Swift']
0
moving-stones-until-consecutive-ii
C++ Code
c-code-by-lucifer_2214-ya54
class Solution {\npublic:\n vector numMovesStonesII(vector& stones) {\n sort(stones.begin(), stones.end());\n\n int N = stones.size(), low = N;
lucifer_2214
NORMAL
2024-06-25T04:06:43.006297+00:00
2024-06-25T04:06:43.006328+00:00
24
false
class Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& stones) {\n sort(stones.begin(), stones.end());\n\n int N = stones.size(), low = N;\n for (int i = 0, j = 0; j < N; ++j) {\n while (stones[j] - stones[i] + 1 > N) {\n ++i;\n }\n ...
0
0
['C++']
0
moving-stones-until-consecutive-ii
Java Code
java-code-by-kpuniya-d81m
class Solution {\n public int[] numMovesStonesII(int[] stones) {\n Arrays.sort(stones);\n\n int i=0, n=stones.length;\n int high = Math.
Kpuniya
NORMAL
2024-06-25T04:02:00.098952+00:00
2024-06-25T04:02:00.098995+00:00
5
false
class Solution {\n public int[] numMovesStonesII(int[] stones) {\n Arrays.sort(stones);\n\n int i=0, n=stones.length;\n int high = Math.max(stones[n-1] - n+2 -stones[1], stones[n-2]-stones[0]- n+2);\n\n int low=n;\n for(int j=0; j<n; j++){\n while(stones[j]-stones[i] >= ...
0
0
[]
0
moving-stones-until-consecutive-ii
Sliding Window with edge case
sliding-window-with-edge-case-by-3aarong-sz5r
\n\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& stones) {\n vector<int> res;\n sort(stones.begin(),stones.end());\n
3aarongan
NORMAL
2024-06-14T18:39:14.778877+00:00
2024-06-14T18:39:14.778907+00:00
20
false
\n```\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& stones) {\n vector<int> res;\n sort(stones.begin(),stones.end());\n int n = stones.size();\n int l = 0, r = 0;\n int result = 0;\n while(l < n){\n while(r < n && stones[r]-stones[l] < n){...
0
0
['C++']
0
moving-stones-until-consecutive-ii
USACO 2019 February Contest, Silver Problem 1. Sleepy Cow Herding
usaco-2019-february-contest-silver-probl-ieza
This is USACO 2019 February Contest, Silver, Problem 1. Sleepy Cow Herding\n\nIt\'s medium, if you\'re in the contest :)\n\nHow to solve it? https://www.youtube
vokasik
NORMAL
2024-06-07T03:03:53.389208+00:00
2024-06-07T03:03:53.389234+00:00
94
false
This is [USACO 2019 February Contest, Silver, Problem 1. Sleepy Cow Herding](]https://usaco.org/index.php?page=viewproblem2&cpid=918)\n\nIt\'s medium, if you\'re in the contest :)\n\nHow to solve it? https://www.youtube.com/watch?v=BvgV7f3pwcI\n\n```\nclass Solution:\n def numMovesStonesII(self, stones: List[int]) -...
0
0
['Python', 'Python3']
1
moving-stones-until-consecutive-ii
1040. Moving Stones Until Consecutive II.cpp
1040-moving-stones-until-consecutive-iic-1yfl
Code\n\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& stones) {\n sort(stones.begin(), stones.end());\n int n = stones.
202021ganesh
NORMAL
2024-04-28T09:43:00.204857+00:00
2024-04-28T09:43:00.204891+00:00
32
false
**Code**\n```\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& stones) {\n sort(stones.begin(), stones.end());\n int n = stones.size(), i = 0, low = n;\n int high = max(stones[n-1] - n + 2 - stones[1], stones[n-2] - stones[0] - n + 2);\n for (int j = 0; j < n; ++j) {...
0
0
['C']
0
moving-stones-until-consecutive-ii
Solution Moving Stones Until Consecutive
solution-moving-stones-until-consecutive-40d2
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
Suyono-Sukorame
NORMAL
2024-03-15T06:55:08.657176+00:00
2024-03-15T06:55:08.657201+00:00
4
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
['PHP']
0
moving-stones-until-consecutive-ii
DAY75 || ABHINAV
day75-abhinav-by-abhijha1-1ai7
Intuition\n Describe your first thoughts on how to solve this problem. \n1. Sort the stones to make it easier to analyze the positions. Find the minimum number
abhijha1
NORMAL
2024-02-08T18:26:19.853088+00:00
2024-02-08T19:51:36.658825+00:00
35
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n1. Sort the stones to make it easier to analyze the positions. Find the minimum number of moves required to make the stones consecutive by iterating through the sorted list of stones.\n\n# Approach\n<!-- Describe your approach to solving ...
0
0
['C++']
0
moving-stones-until-consecutive-ii
Moving Stones Until Consecutive II || JAVASCRIPT || Solution by Bharadwaj
moving-stones-until-consecutive-ii-javas-hryn
Approach\nSliding Window\n\n# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(1)\n\n# Code\n\nvar numMovesStonesII = function(stones) {\n st
Manu-Bharadwaj-BN
NORMAL
2023-12-18T11:29:17.454734+00:00
2023-12-18T11:29:17.454765+00:00
27
false
# Approach\nSliding Window\n\n# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\nO(1)\n\n# Code\n```\nvar numMovesStonesII = function(stones) {\n stones.sort((a, b) => a - b);\n let { length: size } = stones;\n let max = Math.max(stones[size - 1] - stones[1] - size + 2, stones[size - 2] - stones[0] -...
0
0
['JavaScript']
0
moving-stones-until-consecutive-ii
aaa
aaa-by-user3043sb-ckyv
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
user3043SB
NORMAL
2023-12-17T10:06:38.355520+00:00
2023-12-17T10:06:38.355542+00:00
105
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
moving-stones-until-consecutive-ii
Solution
solution-by-deleted_user-1icu
C++ []\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& A) {\n sort(A.begin(), A.end());\n int i = 0, n = A.size(), low =
deleted_user
NORMAL
2023-05-25T08:49:10.107167+00:00
2023-05-25T09:17:37.544366+00:00
293
false
```C++ []\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& A) {\n sort(A.begin(), A.end());\n int i = 0, n = A.size(), low = n;\n int high = max(A[n - 1] - n + 2 - A[1], A[n - 2] - A[0] - n + 2);\n for (int j = 0; j < n; ++j) {\n while (A[j] - A[i] >= n) +...
0
0
['C++', 'Java', 'Python3']
0
moving-stones-until-consecutive-ii
Swift solution with comments, using sliding window
swift-solution-with-comments-using-slidi-7kjs
Complexity\n- Time complexity: O(n*log(n)), where n is stones count\n- Space complexity: O(n)\n\n# Code\n\nclass Solution {\n func numMovesStonesII(_ stones:
VladimirTheLeet
NORMAL
2023-04-12T20:27:02.321607+00:00
2023-04-12T20:30:44.014595+00:00
33
false
# Complexity\n- Time complexity: O(n*log(n)), where n is stones count\n- Space complexity: O(n)\n\n# Code\n```\nclass Solution {\n func numMovesStonesII(_ stones: [Int]) -> [Int]\n {\n let stonesCount = stones.count\n let stones = stones.sorted() // that gives O(n*log(n)) complexity\n\n // di...
0
0
['Swift', 'Sliding Window']
0
moving-stones-until-consecutive-ii
C
c-by-tinachien-azy7
\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint cmp(const void* a, const void* b){\n return *(int*)a - *(int*)b ;\
TinaChien
NORMAL
2023-03-19T12:08:12.747740+00:00
2023-03-19T12:08:12.747772+00:00
34
false
```\n/**\n * Note: The returned array must be malloced, assume caller calls free().\n */\nint cmp(const void* a, const void* b){\n return *(int*)a - *(int*)b ;\n}\nint* numMovesStonesII(int* stones, int stonesSize, int* returnSize){\n int n = stonesSize ;\n *returnSize = 2 ;\n qsort(stones, n, sizeof(int), ...
0
0
[]
0
moving-stones-until-consecutive-ii
C++||Sliding Window|| Easy to Understand
csliding-window-easy-to-understand-by-re-enp3
\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& stones) \n {\n sort(stones.begin(),stones.end());\n int n=stones.siz
return_7
NORMAL
2023-02-13T08:39:09.583980+00:00
2023-02-13T08:39:09.584013+00:00
95
false
```\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& stones) \n {\n sort(stones.begin(),stones.end());\n int n=stones.size();\n int low=n;\n for(int i=0,j=0;j<n;j++)\n {\n while(stones[j]-stones[i]+1>n)\n i++;\n int alre...
0
0
['C', 'Sorting']
0
moving-stones-until-consecutive-ii
Fast C++ solution
fast-c-solution-by-obose-qlk0
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem is to find the minimum number of moves required to move all the stones to c
Obose
NORMAL
2023-01-20T18:28:54.094064+00:00
2023-01-20T18:28:54.094110+00:00
123
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem is to find the minimum number of moves required to move all the stones to consecutive positions. We need to find the minimum number of moves required to move the stones to their final positions and the maximum number of moves ...
0
0
['C++']
0
moving-stones-until-consecutive-ii
Clean Python | 8 Lines | High Speed | O(n) time, O(1) space | Beats 96.9% | With Explanation
clean-python-8-lines-high-speed-on-time-x7sy3
Intuition & Approach\n\n## Lower Bound\nAs I mentioned in my video last week,\nin case of n stones,\nwe need to find a consecutive n positions and move the ston
avs-abhishek123
NORMAL
2023-01-19T06:15:20.822605+00:00
2023-01-19T06:15:20.822650+00:00
170
false
# Intuition & Approach\n\n## Lower Bound\nAs I mentioned in my video last week,\nin case of `n` stones,\nwe need to find a consecutive `n` positions and move the stones in.\n\nThis idea led the solution with sliding windows.\n\nSlide a window of size `N`, and find how many stones are already in this window.\nWe want mo...
0
2
['Python3']
0
moving-stones-until-consecutive-ii
Just a runnable solution
just-a-runnable-solution-by-ssrlive-awgh
Code\n\nimpl Solution {\n pub fn num_moves_stones_ii(stones: Vec<i32>) -> Vec<i32> {\n let mut stones = stones;\n stones.sort();\n let n
ssrlive
NORMAL
2023-01-11T07:53:49.945791+00:00
2023-01-11T07:53:49.945834+00:00
66
false
# Code\n```\nimpl Solution {\n pub fn num_moves_stones_ii(stones: Vec<i32>) -> Vec<i32> {\n let mut stones = stones;\n stones.sort();\n let n = stones.len();\n let mut i = 0;\n let mut low = n as i32;\n let high = std::cmp::max(stones[n - 1] - n as i32 + 2 - stones[1], stone...
0
0
['Rust']
0
moving-stones-until-consecutive-ii
Python solution: try to explain more extensively
python-solution-try-to-explain-more-exte-hxxh
First thing first, this problem is ridiculous to be used for interviews. The given example 2 is actually an edge case....\n\n\nclass Solution:\n # This probl
huikinglam02
NORMAL
2022-08-21T07:31:31.408332+00:00
2022-08-21T07:31:31.408375+00:00
68
false
First thing first, this problem is ridiculous to be used for interviews. The given example 2 is actually an edge case....\n\n```\nclass Solution:\n # This problem is separated into two parts: the max and the min\n # They use totally different strategies\n # Max is a little easier: it involves moving all the st...
0
0
[]
0
moving-stones-until-consecutive-ii
C++| Sliding Window for min + Greedy for max | O(n)
c-sliding-window-for-min-greedy-for-max-86xsz
\nclass Solution {\npublic:\n int cal_min(vector<int>& nums){\n unordered_map<int,int> mp; \n int left = 0, m = INT_MAX;\n for(int i = 0
kumarabhi98
NORMAL
2022-07-02T08:24:05.218782+00:00
2022-07-02T08:24:05.218848+00:00
209
false
```\nclass Solution {\npublic:\n int cal_min(vector<int>& nums){\n unordered_map<int,int> mp; \n int left = 0, m = INT_MAX;\n for(int i = 0; i<nums.size();++i) mp[nums[i]] = i;\n for(int i = 0; i<nums.size();++i){\n int e = nums[i]+nums.size()-1;\n if(e>nums[nums.siz...
0
0
['C', 'Sliding Window']
0
moving-stones-until-consecutive-ii
What is max move and what is min?
what-is-max-move-and-what-is-min-by-rand-uauq
The question huanted me for a while is that what does it mean by max and min move?\nTake max first - how to make sure we move as many times as possible?\nThe an
randysheriff
NORMAL
2022-01-20T21:17:33.332852+00:00
2022-01-20T21:29:51.585592+00:00
239
false
The question huanted me for a while is that what does it mean by max and min move?\nTake max first - how to make sure we move as many times as possible?\nThe answer is to visit as many gaps as we can. Assume we have [7,4,9], after sort, it is [4,7,9], the number of visitable gaps between each pair of positions are 2 an...
0
0
[]
0
moving-stones-until-consecutive-ii
[Python3] sliding window
python3-sliding-window-by-ye15-imfl
\n\nclass Solution:\n def numMovesStonesII(self, stones: List[int]) -> List[int]:\n stones.sort()\n high = max(stones[-1] - stones[1], stones[-
ye15
NORMAL
2021-06-24T16:56:55.349729+00:00
2021-06-24T17:02:30.915382+00:00
312
false
\n```\nclass Solution:\n def numMovesStonesII(self, stones: List[int]) -> List[int]:\n stones.sort()\n high = max(stones[-1] - stones[1], stones[-2] - stones[0]) - (len(stones) - 2)\n \n ii, low = 0, inf\n for i in range(len(stones)): \n while stones[i] - stones[ii] >= l...
0
0
['Python3']
0
moving-stones-until-consecutive-ii
Go | 100% speed + mem
go-100-speed-mem-by-ducthanh98-4zj6
\nfunc numMovesStonesII(stones []int) []int {\n\tsort.Ints(stones)\n\treturn []int{minStep(stones),maxStep(stones)}\n}\n\nfunc minStep(stones []int) int {\n\tle
ducthanh98
NORMAL
2021-06-20T14:29:50.690333+00:00
2021-06-20T14:29:50.690364+00:00
130
false
```\nfunc numMovesStonesII(stones []int) []int {\n\tsort.Ints(stones)\n\treturn []int{minStep(stones),maxStep(stones)}\n}\n\nfunc minStep(stones []int) int {\n\tleft,right := 0,1\n\tminStep := math.MaxInt32\n\tgaps := 0\n\texistStones := 1\n\tlength := len(stones)\n\tfor right < length {\n\n\t\tif stones[right] <= ston...
0
0
[]
0
moving-stones-until-consecutive-ii
cpp14 solution
cpp14-solution-by-divkr98-81dw
max idea : https://leetcode.com/problems/moving-stones-until-consecutive-ii/discuss/286920/Use-Interval-to-Get-Max-Moves\n\nmin idea : https://leetcode.com/prob
divkr98
NORMAL
2020-10-23T08:47:19.243655+00:00
2020-10-23T08:48:43.514109+00:00
278
false
max idea : https://leetcode.com/problems/moving-stones-until-consecutive-ii/discuss/286920/Use-Interval-to-Get-Max-Moves\n\nmin idea : https://leetcode.com/problems/moving-stones-until-consecutive-ii/discuss/555907/C%2B%2B-solution-or-Sliding-window-for-minimum-moves\n\n\n```\nclass Solution {\npublic:\n\n int calcu...
0
0
[]
0
moving-stones-until-consecutive-ii
Rust translated, 0ms 100%
rust-translated-0ms-100-by-qiuzhanghua-hvwa
rust\nimpl Solution {\n pub fn num_moves_stones_ii(mut a: Vec<i32>) -> Vec<i32> {\n a.sort();\n let mut i = 0;\n let n = a.len();\n
qiuzhanghua
NORMAL
2020-09-18T00:38:22.561633+00:00
2020-09-18T00:38:22.561666+00:00
164
false
```rust\nimpl Solution {\n pub fn num_moves_stones_ii(mut a: Vec<i32>) -> Vec<i32> {\n a.sort();\n let mut i = 0;\n let n = a.len();\n let mut lo = n as i32;\n let hi = std::cmp::max(\n a[n - 1] - n as i32 + 2 - a[1],\n a[n - 2] - a[0] - n as i32 + 2,\n ...
0
0
[]
0
moving-stones-until-consecutive-ii
JavaScript Sliding Window
javascript-sliding-window-by-zckpp1992-z5c8
Maximum\nThe idea of getting the maximum is to use up all the empty slots available.\nAnd since left most item cannot be left most item again and same to right
zckpp1992
NORMAL
2020-08-23T21:28:19.070066+00:00
2020-08-23T21:28:19.070104+00:00
298
false
**Maximum**\nThe idea of getting the maximum is to use up all the empty slots available.\nAnd since left most item cannot be left most item again and same to right most item, we have to move left most item to the right of A[1], and right most item to the left of A[n-2].\nThus all the empty slots available is either A[n...
0
0
[]
0
moving-stones-until-consecutive-ii
[C++] lots of subtle corner cases, learned from forum
c-lots-of-subtle-corner-cases-learned-fr-kywm
\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& stones) {\n const int n = stones.size();\n std::sort(stones.begin(), st
huangdachuan
NORMAL
2020-06-18T05:56:51.381140+00:00
2020-06-18T05:56:51.381190+00:00
317
false
```\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& stones) {\n const int n = stones.size();\n std::sort(stones.begin(), stones.end());\n\n int j = 0;\n for (; j < n && stones[j] - stones[0] + 1 <= n; ++j) {}\n int maxOccupied = j;\n for (int i = 0; j ...
0
0
[]
0
moving-stones-until-consecutive-ii
Miss test case @LeetCodeOffical(Actually not)
miss-test-case-leetcodeofficalactually-n-xyto
If input is [1,5], we cannot make any movements, because all stones are endpoint stones. So the result should be [0,0]. \nHowever, for now, the reuslt from OJ i
hanzhoutang
NORMAL
2020-03-25T04:19:37.842553+00:00
2020-03-25T15:54:49.595235+00:00
184
false
If input is [1,5], we cannot make any movements, because all stones are endpoint stones. So the result should be [0,0]. \nHowever, for now, the reuslt from OJ is [2,0]. \nI believe it\'s a bug, we need to add this testcase. \n@LeetCodeOffical
0
0
[]
1
moving-stones-until-consecutive-ii
c++ solution
c-solution-by-hanzhoutang-ngjy
In my opinion, I think the problem is really not as easy as you think. \n\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& stones) {\n
hanzhoutang
NORMAL
2020-03-25T04:05:10.997508+00:00
2020-03-25T04:21:16.104671+00:00
370
false
In my opinion, I think the problem is really not as easy as you think. \n```\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& stones) {\n if(stones.empty()||stones.size()==1){\n return {0,0};\n }\n if(stones.size() == 2){\n return {0,0};\n }\n ...
0
0
[]
0
moving-stones-until-consecutive-ii
[python] 100%
python-100-by-fukuzawa_yumi-l6kf
\n def numMovesStonesII(self, stones):\n stones.sort()\n n,i=len(stones),0\n for j in range(n):\n if stones[j]-stones[i]>=n:
fukuzawa_yumi
NORMAL
2020-01-21T05:28:51.240380+00:00
2020-01-21T05:28:51.240414+00:00
387
false
```\n def numMovesStonesII(self, stones):\n stones.sort()\n n,i=len(stones),0\n for j in range(n):\n if stones[j]-stones[i]>=n: i+=1\n return [2 if i==1 and stones[-1]-stones[0]!=n and (stones[-2]-stones[0]==n-2 or stones[-1]-stones[1]==n-2) else i,stones[-1]-stones[0]-n-min(st...
0
1
[]
1
moving-stones-until-consecutive-ii
Go solution
go-solution-by-sabakunoarashi-llt8
go\nimport "sort"\n\nfunc max(a, b int) int {\n if a > b {\n return a\n } else {\n return b\n }\n}\n\nfunc min(a, b int) int {\n if a
sabakunoarashi
NORMAL
2019-12-19T15:22:56.964442+00:00
2019-12-19T15:22:56.964489+00:00
118
false
```go\nimport "sort"\n\nfunc max(a, b int) int {\n if a > b {\n return a\n } else {\n return b\n }\n}\n\nfunc min(a, b int) int {\n if a > b {\n return b\n } else {\n return a\n }\n}\n\nfunc numMovesStonesII(stones []int) []int {\n sort.Ints(stones)\n i, n := 0, len(s...
0
0
[]
0
moving-stones-until-consecutive-ii
C++ solution 10~20ms
c-solution-1020ms-by-danyanglee-98fk
\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& A) {\n int mx = 0, sz = A.size(), i = A[0], l = 0, r = 0;\n vector<int>
danyanglee
NORMAL
2019-11-03T08:48:31.095882+00:00
2019-11-03T08:56:25.020513+00:00
318
false
```\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& A) {\n int mx = 0, sz = A.size(), i = A[0], l = 0, r = 0;\n vector<int> res;\n ios::sync_with_stdio(false);\n \n sort(A.begin(), A.end());\n \n while(r < sz && A[r] <= A[0]+sz-1) r++;\n...
0
0
[]
0
moving-stones-until-consecutive-ii
C++ sliding window solution
c-sliding-window-solution-by-eminem18753-q5lz
\nclass Solution \n{\n public:\n vector<int> numMovesStonesII(vector<int>& a) \n {\n int n=a.size();\n sort(a.begin(),a.end());\n
eminem18753
NORMAL
2019-10-08T02:56:48.881374+00:00
2019-10-08T02:56:48.881412+00:00
474
false
```\nclass Solution \n{\n public:\n vector<int> numMovesStonesII(vector<int>& a) \n {\n int n=a.size();\n sort(a.begin(),a.end());\n int M=max(a[n-2]-a[0]-n+2,a[n-1]-a[1]-n+2);\n int m=2147483647;\n \n int p1=0;\n int p2=0;\n while(true)\n {\n ...
0
0
[]
0
moving-stones-until-consecutive-ii
C++ O(NlogN) solution
c-onlogn-solution-by-jokerkeny-9z14
\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& stones) {\n sort(stones.begin(),stones.end());\n int n = stones.size();
jokerkeny
NORMAL
2019-05-05T04:10:14.097606+00:00
2019-05-05T04:21:47.846037+00:00
646
false
```\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& stones) {\n sort(stones.begin(),stones.end());\n int n = stones.size();\n int minmove = n;\n \n auto i = stones.begin();\n auto j = upper_bound(stones.begin(), stones.end(), stones[0]+n-1);\n m...
0
0
['C']
1
moving-stones-until-consecutive-ii
C++ O(N log(N))
c-on-logn-by-murkyautomata-q6ez
\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& stones) {\n int N= stones.size(), max_in_N=0, min_steps, max_steps, first_gap;
murkyautomata
NORMAL
2019-05-05T04:06:59.083496+00:00
2019-05-05T04:07:33.463681+00:00
351
false
```\nclass Solution {\npublic:\n vector<int> numMovesStonesII(vector<int>& stones) {\n int N= stones.size(), max_in_N=0, min_steps, max_steps, first_gap;\n \n if(N<3) return {0,0};\n \n sort(stones.begin(), stones.end());\n \n for(int i=0, j=0; i<N; ++i){\n ...
0
0
[]
0
network-delay-time
Java, Djikstra/bfs, Concise and very easy to understand
java-djikstrabfs-concise-and-very-easy-t-1qt4
I think bfs and djikstra are very similar problems. It\'s just that djikstra cost is different compared with bfs, so use priorityQueue instead a Queue for a sta
alizhiyu46
NORMAL
2018-12-28T21:39:46.215798+00:00
2019-06-16T22:41:05.329730+00:00
55,694
false
I think bfs and djikstra are very similar problems. It\'s just that djikstra cost is different compared with bfs, so use priorityQueue instead a Queue for a standard bfs search.\n```\nclass Solution {\n public int networkDelayTime(int[][] times, int N, int K) {\n Map<Integer, Map<Integer,Integer>> map = new H...
292
9
[]
36
network-delay-time
[C++] Bellman Ford
c-bellman-ford-by-alexander-7buu
C++\n\nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int N, int K) {\n vector<int> dist(N + 1, INT_MAX);\n dist[
alexander
NORMAL
2017-12-10T04:01:53.214000+00:00
2018-10-21T03:47:07.559308+00:00
33,922
false
**C++**\n```\nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int N, int K) {\n vector<int> dist(N + 1, INT_MAX);\n dist[K] = 0;\n for (int i = 0; i < N; i++) {\n for (vector<int> e : times) {\n int u = e[0], v = e[1], w = e[2];\n ...
233
10
[]
37
network-delay-time
Python concise queue & heap solutions
python-concise-queue-heap-solutions-by-c-dtvk
Heap\n\nclass Solution:\n def networkDelayTime(self, times, N, K):\n q, t, adj = [(0, K)], {}, collections.defaultdict(list)\n for u, v, w in t
cenkay
NORMAL
2018-10-30T14:07:26.087090+00:00
2018-10-30T14:07:26.087153+00:00
20,656
false
* Heap\n```\nclass Solution:\n def networkDelayTime(self, times, N, K):\n q, t, adj = [(0, K)], {}, collections.defaultdict(list)\n for u, v, w in times:\n adj[u].append((v, w))\n while q:\n time, node = heapq.heappop(q)\n if node not in t:\n t[nod...
158
2
['Queue', 'Heap (Priority Queue)', 'Python']
20
network-delay-time
[c++] Easy to understand Dijkstra's algorithm
c-easy-to-understand-dijkstras-algorithm-dg76
\ntypedef pair<int, int> pii;\n\nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int n, int k) {\n vector<vector<pii> > g
flyingmouse
NORMAL
2018-09-25T19:48:14.623051+00:00
2022-04-20T09:51:28.593678+00:00
39,305
false
```\ntypedef pair<int, int> pii;\n\nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int n, int k) {\n vector<vector<pii> > g(n + 1);\n for (const auto& t : times) {\n g[t[0]].emplace_back(t[1], t[2]);\n }\n const int inf = 1e9;\n vector<int> ...
144
7
[]
23
network-delay-time
Java solutions using Dijkstra, Floyd–Warshall and Bellman-Ford algorithm
java-solutions-using-dijkstra-floyd-wars-qrni
Floyd\u2013Warshall algorithm\nTime complexity: O(N^3), Space complexity: O(N^2)\n\npublic int networkDelayTime_FW(int[][] times, int N, int K) {\n double[][
lakemorning
NORMAL
2018-10-21T03:12:24.978940+00:00
2018-10-24T13:19:29.959742+00:00
16,528
false
1. Floyd\u2013Warshall algorithm\nTime complexity: O(N^3), Space complexity: O(N^2)\n```\npublic int networkDelayTime_FW(int[][] times, int N, int K) {\n double[][] disTo = new double[N][N];\n for (int i = 0; i < N; i++) {\n Arrays.fill(disTo[i], Double.POSITIVE_INFINITY);\n }\n for (int i = 0; i < N...
133
1
[]
19
network-delay-time
Python Bellman-Ford, SPFA, Dijkstra, Floyd, clean and easy to understand
python-bellman-ford-spfa-dijkstra-floyd-3hnmg
Since the input is edges, it naturally occured to me to use Bellman-Ford. Of course we can process the edges and use SPFA (Shortest Path Faster Algorithm) and D
sfdye
NORMAL
2019-04-29T12:53:42.168292+00:00
2019-04-29T12:53:42.168338+00:00
10,395
false
Since the input is edges, it naturally occured to me to use Bellman-Ford. Of course we can process the edges and use [SPFA](https://en.wikipedia.org/wiki/Shortest_Path_Faster_Algorithm) (Shortest Path Faster Algorithm) and Dijkstra.\n\n**Bellman-Ford**\nTime: `O(VE)`\nSpace: `O(N)`\n\n```python\nclass Solution:\n de...
121
0
[]
12
network-delay-time
[Python] - DFS, BFS, Dijkstra, Bellman Ford, SPFA, Floyd Warshall
python-dfs-bfs-dijkstra-bellman-ford-spf-jw6b
\nimport heapq\nfrom collections import deque\nfrom collections import defaultdict\n\n# """\n# Uses simple DFS - Accepted\nclass Solution(object):\n def net
parthobiswas007
NORMAL
2020-01-05T09:00:23.670647+00:00
2021-11-28T17:34:39.476394+00:00
10,204
false
```\nimport heapq\nfrom collections import deque\nfrom collections import defaultdict\n\n# """\n# Uses simple DFS - Accepted\nclass Solution(object):\n def networkDelayTime(self, times, N, K):\n graph = defaultdict(list)\n for u, v, w in times:\n graph[u].append((v, w))\n distance = ...
87
2
['Depth-First Search', 'Breadth-First Search', 'Python']
9
network-delay-time
Python Simple Dijkstra Beats ~90%
python-simple-dijkstra-beats-90-by-const-p64k
Time - O(N + ELogN) -Standard Time complexity of Dijkstra\'s algorithm\n\nSpace - O(N + E) - for adjacency list and maintaining Heap.\n\n\nclass Solution:\n
constantine786
NORMAL
2022-05-14T03:13:19.541575+00:00
2022-05-14T03:29:46.795649+00:00
8,776
false
**Time - O(N + ELogN)** -Standard Time complexity of [Dijkstra\'s algorithm](https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm#Running_time)\n\n**Space - O(N + E)** - for adjacency list and maintaining Heap.\n\n```\nclass Solution:\n def networkDelayTime(self, times: List[List[int]], n: int, k: int) -> int: ...
66
0
['Python', 'Python3']
4
network-delay-time
[C++] Djikstra's Algorithm (Very Easy To Understand) (Beats 85%)
c-djikstras-algorithm-very-easy-to-under-yj08
\n // Using Priority queue (Min-heap)\n int networkDelayTime(vector<vector<int>>& times, int N, int K) {\n vector<pair<int,int>> g[N+1];\n f
not_a_cp_coder
NORMAL
2020-07-17T21:23:22.026165+00:00
2020-07-17T21:23:22.026206+00:00
10,908
false
```\n // Using Priority queue (Min-heap)\n int networkDelayTime(vector<vector<int>>& times, int N, int K) {\n vector<pair<int,int>> g[N+1];\n for(int i=0;i<times.size();i++)\n g[times[i][0]].push_back(make_pair(times[i][1],times[i][2]));\n vector<int> dist(N+1, 1e9);\n dist[...
56
2
['C', 'Heap (Priority Queue)', 'C++']
6
network-delay-time
Dijkstra's Algorithm - Template - List of Problems
dijkstras-algorithm-template-list-of-pro-8xbv
Dijlstra\'s Algorithm\n\n743. Network Delay Time\n\n\n/*\nStep 1: Create a Map of start and end nodes with weight\n 1 -> {2,1},{3,2}\n 2 -> {4,4},
letsdoitthistime
NORMAL
2022-07-21T01:33:17.762402+00:00
2024-02-12T03:37:51.604706+00:00
8,309
false
Dijlstra\'s Algorithm\n\n**743. Network Delay Time**\n\n```\n/*\nStep 1: Create a Map of start and end nodes with weight\n 1 -> {2,1},{3,2}\n 2 -> {4,4},{5,5}\n 3 -> {5,3}\n 4 ->\n 5 ->\n\nStep 2: create a result array where we will keep track the minimum distance to rech end of the n...
55
0
['Java']
7
network-delay-time
[C++] 3 Solutions ( BFS, Dijkstra, Bellman-Ford )
c-3-solutions-bfs-dijkstra-bellman-ford-uzo63
BFS \nTC = 108ms\n\nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int n, int k) {\n vector<pair<int,int>> adj[n+1];\n
sheldonbang
NORMAL
2021-05-19T15:44:22.077697+00:00
2021-08-19T03:35:21.553539+00:00
4,969
false
**BFS** \n*TC = 108ms*\n```\nclass Solution {\npublic:\n int networkDelayTime(vector<vector<int>>& times, int n, int k) {\n vector<pair<int,int>> adj[n+1];\n for(int i=0;i<times.size();i++)\n adj[times[i][0]].push_back({times[i][1],times[i][2]});\n vector<int> dist(n+1,INT_MAX);\n...
41
0
['Breadth-First Search', 'C', 'C++']
3
network-delay-time
Efficient O(E log V) Python Dijkstra min heap with explanation
efficient-oe-log-v-python-dijkstra-min-h-h2ih
Good video to visualize what\'s happening in Dijkstra with minimal fuss https://www.youtube.com/watch?v=pVfj6mxhdMw\n\nPython implementation details:\n\n1. Cons
mereck
NORMAL
2019-07-07T16:26:31.358865+00:00
2019-07-07T16:46:05.129240+00:00
19,294
false
Good video to visualize what\'s happening in Dijkstra with minimal fuss https://www.youtube.com/watch?v=pVfj6mxhdMw\n\nPython implementation details:\n\n1. Construct adjacency list representation of a directional graph using a defaultdict of dicts\n2. Track visited vertices in a set\n3. Track known distances from K to ...
37
0
[]
5
network-delay-time
Simple JAVA Djikstra's (PriorityQueue optimized) Solution with explanation
simple-java-djikstras-priorityqueue-opti-wxhp
It is a direct graph. \n1. Use Map> to store the source node, target node and the distance between them.\n2. Offer the node K to a PriorityQueue.\n3. Then keep
samuel_ji
NORMAL
2017-12-16T00:04:42.431000+00:00
2018-10-24T04:33:31.185932+00:00
18,076
false
It is a direct graph. \n1. Use Map<Integer, Map<Integer, Integer>> to store the source node, target node and the distance between them.\n2. Offer the node K to a PriorityQueue.\n3. Then keep getting the closest nodes to the current node and calculate the distance from the source (K) to this node (absolute distance). Us...
36
4
[]
16
network-delay-time
Not sure why this is a medium
not-sure-why-this-is-a-medium-by-elmubar-tzsh
This seems like a problem that should be labeled hard. Dijkstra\'s isn\'t a super commonly known algorithm.
elmubark
NORMAL
2018-09-14T16:29:33.980764+00:00
2018-09-14T16:29:33.980810+00:00
6,069
false
This seems like a problem that should be labeled hard. Dijkstra\'s isn\'t a super commonly known algorithm.
34
12
[]
15