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
house-robber-iii
Simple Java Recursion+Memoization solution
simple-java-recursionmemoization-solutio-cknk
Time O(n) | Space O(n)\n DP on trees\n \twe can choose b/w grandchildren+parent or children\n\n\n HashMap<TreeNode, Integer> map=new HashMap<>();\n public
shahbaz_07
NORMAL
2020-11-28T20:22:25.230768+00:00
2020-11-28T20:22:25.230799+00:00
331
false
* Time O(n) | Space O(n)\n* DP on trees\n* \twe can choose b/w grandchildren+parent or children\n```\n\n HashMap<TreeNode, Integer> map=new HashMap<>();\n public int rob(TreeNode root) {\n //we can choose b/w grandchildren+parent or children\n if(root==null)return 0;\n \n if(map.contai...
4
0
['Dynamic Programming', 'Memoization', 'Java']
0
house-robber-iii
[Python 3] Explained Solution (video + code)
python-3-explained-solution-video-code-b-b4gq
\nhttps://www.youtube.com/watch?v=mSzz_bZUVCQ\n\nclass Solution:\n def rob(self, root: TreeNode) -> int:\n @lru_cache(None)\n \n def hel
spec_he123
NORMAL
2020-11-23T16:25:53.990575+00:00
2020-11-23T16:25:53.990610+00:00
409
false
[](https://www.youtube.com/watch?v=mSzz_bZUVCQ)\nhttps://www.youtube.com/watch?v=mSzz_bZUVCQ\n```\nclass Solution:\n def rob(self, root: TreeNode) -> int:\n @lru_cache(None)\n \n def helper(node, parent_stolen):\n if not node:\n return 0\n \n if pa...
4
0
['Recursion', 'Python', 'Python3']
0
house-robber-iii
Rust dfs solution
rust-dfs-solution-by-sugyan-0ex6
rust\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn rob(root: Option<Rc<RefCell<TreeNode>>>) -> i32 {\n let ret = Solution::dfs(
sugyan
NORMAL
2020-11-23T13:25:07.751543+00:00
2020-11-23T13:25:07.751574+00:00
144
false
```rust\nuse std::rc::Rc;\nuse std::cell::RefCell;\nimpl Solution {\n pub fn rob(root: Option<Rc<RefCell<TreeNode>>>) -> i32 {\n let ret = Solution::dfs(&root);\n std::cmp::max(ret.0, ret.1)\n }\n fn dfs(node: &Option<Rc<RefCell<TreeNode>>>) -> (i32, i32) {\n if let Some(n) = node {\n ...
4
0
['Depth-First Search', 'Rust']
0
house-robber-iii
JavaScript recursion solution
javascript-recursion-solution-by-sao_mai-jlwq
Max at root is either the sum of max left subtree and max right subtree, or the sum of the root with max of left subtree children and max of right subtree child
sao_mai
NORMAL
2020-10-18T20:46:36.520827+00:00
2020-10-18T20:46:36.520868+00:00
426
false
Max at root is either the sum of max left subtree and max right subtree, or the sum of the root with max of left subtree children and max of right subtree children. The key here is that you want to return both the max at the root and the max of its children in the helper method.\n```\n/**\n * Definition for a binary tr...
4
0
['Recursion', 'JavaScript']
0
house-robber-iii
Python DP Soln
python-dp-soln-by-srajsonu-12pj
\nclass Solution:\n def dp(self, root, dp):\n if not root: return 0\n if root in dp:\n return dp[root]\n \n val = 0\n
srajsonu
NORMAL
2020-08-21T05:42:25.021440+00:00
2020-08-21T05:42:25.021482+00:00
302
false
```\nclass Solution:\n def dp(self, root, dp):\n if not root: return 0\n if root in dp:\n return dp[root]\n \n val = 0\n if root.left:\n val += self.dp(root.left.left, dp) + self.dp(root.left.right, dp)\n \n if root.right:\n val += sel...
4
0
['Memoization', 'Python']
2
house-robber-iii
GOOGLE INTERVIEW QUESTION | DP | INTUITIVE EXPLANATION !!
google-interview-question-dp-intuitive-e-4dq4
It is same as the question https://leetcode.com/problems/house-robber/ but now we have to steal in a Binary Tree. At that question We have used our DP as maxim
prajwalpant15
NORMAL
2020-08-06T13:18:30.606542+00:00
2020-08-06T13:27:01.800466+00:00
365
false
It is same as the question https://leetcode.com/problems/house-robber/ but now we have to steal in a Binary Tree. At that question We have used our DP as maximum profit at ith index if we pick value at ith index or we do not pick the value at ith index.\n\nHere We have to use the same Dp state but we have to use it to...
4
0
[]
1
house-robber-iii
Python Intuitive O(n) solution
python-intuitive-on-solution-by-bovinova-jmlf
For each node, compute the maximum money whether choosing the node or not.\n```\nclass Solution:\n def rob(self, root: TreeNode) -> int:\n \n d
bovinovain
NORMAL
2020-08-05T21:53:40.098658+00:00
2020-08-05T21:53:40.098693+00:00
172
false
For each node, compute the maximum money whether choosing the node or not.\n```\nclass Solution:\n def rob(self, root: TreeNode) -> int:\n \n def check(root): \n\t\t# return a tuple (choosing the root, not choosing the root)\n if not root:\n return (0,0)\n left = ch...
4
0
[]
1
house-robber-iii
C++ DP solution with a vector to store two states
c-dp-solution-with-a-vector-to-store-two-gh65
In this code, at every node, it returns a vector storing two states : rob this node or not rob\nres[0] means the max value I can get from the botton if I rob th
AL2O3_yhl
NORMAL
2020-05-23T16:48:00.676603+00:00
2020-05-23T16:48:00.676648+00:00
364
false
In this code, at every node, it returns a vector storing two states : rob this node or not rob\nres[0] means the max value I can get from the botton **if I rob this node**\nres[1] means the max value I can get from the botton **if I don\'t rob this node**\nTime O(n) the recu will visit every node\nSpace O(1n) every nod...
4
0
['Dynamic Programming', 'C', 'C++']
1
house-robber-iii
[Python] DFS solution with explanations
python-dfs-solution-with-explanations-by-shy4
Explanations:\nFor each node, the robber can either rob this node and leave out the consecutive left and right nodes, or he/she can not rob this node and try ou
codingasiangirll
NORMAL
2020-05-06T18:34:23.652639+00:00
2020-05-06T18:36:28.303121+00:00
112
false
**Explanations**:\nFor each node, the robber can either rob this node and leave out the consecutive left and right nodes, or he/she can not rob this node and try out different combinations to find the max value that he/she can rob. The combinations include rob 1. both left and right nodes, 2. rob only left node and not...
4
0
[]
0
house-robber-iii
Go 4ms very simple
go-4ms-very-simple-by-tjucoder-wg43
go\nfunc rob(root *TreeNode) int {\n\treturn max(robber(root))\n}\n\nfunc robber(node *TreeNode) (int, int) {\n\tif node == nil {\n\t\treturn 0, 0\n\t}\n\tgold
tjucoder
NORMAL
2020-04-07T13:19:11.066108+00:00
2020-04-07T13:19:11.066145+00:00
242
false
```go\nfunc rob(root *TreeNode) int {\n\treturn max(robber(root))\n}\n\nfunc robber(node *TreeNode) (int, int) {\n\tif node == nil {\n\t\treturn 0, 0\n\t}\n\tgold := node.Val\n\tl1, l2 := robber(node.Left)\n\tr1, r2 := robber(node.Right)\n\tc1 := gold + l2 + r2\n\tc2 := max(l1, l2) + max(r1, r2)\n\treturn c1, c2\n}\n\n...
4
0
['Go']
0
house-robber-iii
Linear time -- Python
linear-time-python-by-ht_wang-tint
Same logic as House Robber\n\ndef rob(self, root):\n """\n :type root: TreeNode\n :rtype: int\n """\n def helper(root):\n
ht_wang
NORMAL
2019-11-30T01:04:26.466300+00:00
2019-11-30T18:46:09.732396+00:00
474
false
Same logic as [House Robber](https://leetcode.com/problems/house-robber/discuss/440346/python-constant-space-O(N))\n```\ndef rob(self, root):\n """\n :type root: TreeNode\n :rtype: int\n """\n def helper(root):\n if not root:\n return 0, 0 \n \n ...
4
0
[]
1
house-robber-iii
Java bottom-up and top-down solutions using DP
java-bottom-up-and-top-down-solutions-us-54w9
The naive solution is straightforward, just traverse the tree and in each node, we either take it or not. If we take it, we cannot take its children, if not ta
yfcheng
NORMAL
2016-03-12T01:44:25+00:00
2016-03-12T01:44:25+00:00
1,287
false
The naive solution is straightforward, just traverse the tree and in each node, we either take it or not. If we take it, we cannot take its children, if not take, we can take either or both of the children. This will cause TLE due to extra calculation. Since this is a house robber problem, DP is the first come to mi...
4
0
[]
1
house-robber-iii
Simple 1ms Java solution with easy comments
simple-1ms-java-solution-with-easy-comme-xfzh
/*\n \u5411\u5de6\u53f3\u4e24\u8fb9\u8981\u6570\u636e, \u9010\u5c42\u5411\u4e0a\u8fd4\u56de\u3002\n \u8fd4\u56de\u7684\u662fint[2] result.\n
mach7
NORMAL
2016-03-12T21:28:09+00:00
2016-03-12T21:28:09+00:00
634
false
/*\n \u5411\u5de6\u53f3\u4e24\u8fb9\u8981\u6570\u636e, \u9010\u5c42\u5411\u4e0a\u8fd4\u56de\u3002\n \u8fd4\u56de\u7684\u662fint[2] result.\n result[0] -- \u62a2\u5f53\u524droot\u6240\u80fd\u5f97\u7684\u6700\u5927\u503c\u3002\n result[1] -- \u4e0d\u62a2\u5f53\u524droot\u6240\u80fd\u5f97\u...
4
1
[]
0
house-robber-iii
6-line Python solution, return (subtree max money if not rob this node, subtree max money)
6-line-python-solution-return-subtree-ma-r719
def rob(self, root):\n def dfs(node):\n # return (subtree max money if not rob this node, subtree max money)\n if not node: return
kitt
NORMAL
2016-03-21T16:59:12+00:00
2016-03-21T16:59:12+00:00
1,224
false
def rob(self, root):\n def dfs(node):\n # return (subtree max money if not rob this node, subtree max money)\n if not node: return 0, 0\n max_l_ignore, max_l = dfs(node.left)\n max_r_ignore, max_r = dfs(node.right)\n return max_l + max_r, max(max_l + max...
4
0
['Depth-First Search', 'Python']
1
house-robber-iii
Two solutions with Java (1 ms)
two-solutions-with-java-1-ms-by-skoy12-n7qw
public int rob(TreeNode root) {\n if(root==null) return 0;\n rob1(root);\n return root.val;\n }\n public int rob1(TreeNode root){\n
skoy12
NORMAL
2016-04-24T11:45:37+00:00
2016-04-24T11:45:37+00:00
1,333
false
public int rob(TreeNode root) {\n if(root==null) return 0;\n rob1(root);\n return root.val;\n }\n public int rob1(TreeNode root){\n if(root==null) return 0;\n int pre=0;\n root.val+=rob1(root.left)+rob1(root.right);\n if(root.left!=null) pre+=root.left.val;\n ...
4
2
[]
5
house-robber-iii
C++ implementation refer to @fun4LeetCode
c-implementation-refer-to-fun4leetcode-b-lpkb
First naive Solution \n\n class Solution {\n public:\n int rob(TreeNode root) {\n if(root == NULL) return 0;\n int val = 0;\
rainbowsecret
NORMAL
2016-03-20T09:40:58+00:00
2016-03-20T09:40:58+00:00
998
false
First naive Solution \n\n class Solution {\n public:\n int rob(TreeNode* root) {\n if(root == NULL) return 0;\n int val = 0;\n if(root->left) {\n val += rob(root->left->left) + rob(root->left->right);\n }\n if(root->right) {\n ...
4
0
[]
2
house-robber-iii
Short Python solution
short-python-solution-by-dimal97psn-nc24
class Solution(object):\n def rob(self, root):\n def solve(root):\n if not root:\n return 0, 0\n
dimal97psn
NORMAL
2016-06-29T03:32:20+00:00
2016-06-29T03:32:20+00:00
1,089
false
class Solution(object):\n def rob(self, root):\n def solve(root):\n if not root:\n return 0, 0\n left, right = solve(root.left), solve(root.right)\n return (root.val + left[1] + right[1]), (max(left) + max(right))\n return ...
4
0
['Python']
1
house-robber-iii
✅ Easy to Understand | Recursion with Memorization | DP | Detailed Video Explanation🔥
easy-to-understand-recursion-with-memori-i33e
IntuitionThe problem is a variation of the House Robber problem but applied to a binary tree. Since we cannot rob two directly linked houses (nodes), we must ma
sahilpcs
NORMAL
2025-03-15T10:12:49.588469+00:00
2025-03-15T10:13:17.028329+00:00
507
false
# Intuition The problem is a variation of the House Robber problem but applied to a binary tree. Since we cannot rob two directly linked houses (nodes), we must make an optimal choice at each node to maximize the robbed amount. The key observation is that for each node, we have two choices: either rob it and skip its c...
3
0
['Dynamic Programming', 'Tree', 'Depth-First Search', 'Binary Tree', 'Java']
1
house-robber-iii
Easy approach
easy-approach-by-kadir3-u9cz
Intuitionits very effective solution and easy to understand. (first time posting solution)Approachusing dynamic programming to calculate each nodesComplexity T
Kadir3
NORMAL
2025-01-29T07:12:56.421737+00:00
2025-01-29T07:12:56.421737+00:00
514
false
# Intuition its very effective solution and easy to understand. (first time posting solution) # Approach using dynamic programming to calculate each nodes # Complexity - Time complexity: Its very fast - Space complexity: idk # Code ```cpp [] /** * Definition for a binary tree node. * struct TreeNode { * int ...
3
0
['Dynamic Programming', 'C++']
2
house-robber-iii
Let's rob the Houses 🏠 | Simple and Easy Solution ✅✅ | Recursion + Memoization ✅
lets-rob-the-houses-simple-and-easy-solu-sq8z
Intuition\n Describe your first thoughts on how to solve this problem. \nThe problem involves determining the maximum amount of money that can be robbed from a
its_kartike
NORMAL
2024-08-13T09:00:16.569125+00:00
2024-08-13T09:00:16.569156+00:00
356
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe problem involves determining the maximum amount of money that can be robbed from a binary tree of houses without robbing two directly connected houses. My initial thought is to use dynamic programming to track the maximum value that c...
3
0
['Dynamic Programming', 'Tree', 'Recursion', 'Memoization', 'C++']
0
house-robber-iii
[Python3] Easy to understand | Recursive Post-order | Linear time & space
python3-easy-to-understand-recursive-pos-9b19
Intuition\nAt each node, we either need to consider the node iteslf or its children.\n\n# Approach\nFrom each node, return the max we can get by including the n
open_sourcerer_
NORMAL
2023-09-17T20:43:50.845298+00:00
2023-09-17T20:43:50.845321+00:00
398
false
# Intuition\nAt each node, we either need to consider the node iteslf or its children.\n\n# Approach\nFrom each node, return the max we can get by including the node and also max without the node.\n\n1. For base cases (Leaf node\'s Null children), return `[0, 0]`\n2. With postorder traversal, at each node up in recusrs...
3
0
['Python3']
0
house-robber-iii
NeetCode solution|| Clean code
neetcode-solution-clean-code-by-jain_06_-feg1
\n# Code\n\nclass Solution {\npublic:\n\n pair<int,int> helper(TreeNode* root){\n if(root == NULL) return {0,0};\n\n pair<int,int> left1 = help
jain_06_07
NORMAL
2023-07-14T10:13:09.177567+00:00
2023-07-14T10:13:09.177584+00:00
394
false
\n# Code\n```\nclass Solution {\npublic:\n\n pair<int,int> helper(TreeNode* root){\n if(root == NULL) return {0,0};\n\n pair<int,int> left1 = helper(root->left);\n pair<int,int> right1 = helper(root->right);\n\n int with = root->val + left1.second + right1.second ;\n int without = ...
3
0
['C++']
1
maximum-path-quality-of-a-graph
[Python] short dfs, explained
python-short-dfs-explained-by-dbabichev-n3c6
Key to success in this problem is to read problem constraints carefully: I spend like 10 minutes before I understand that problem can be solved using very simpl
dbabichev
NORMAL
2021-11-07T04:00:45.482990+00:00
2021-11-07T04:00:45.483025+00:00
8,055
false
Key to success in this problem is to read problem constraints carefully: I spend like 10 minutes before I understand that problem can be solved using very simple dfs. Why? Because it is given that `maxTime <= 100` and `time_j >= 10`. It means that we can make no more than `10` steps in our graph! So, all we need to do ...
130
4
['Depth-First Search']
15
maximum-path-quality-of-a-graph
Simple DFS solution (C++)
simple-dfs-solution-c-by-byte_walker-nme8
We will do DFS in this problem. We have the condition here that we can visit a node any number of times but we shall add its value only once for that path for t
Byte_Walker
NORMAL
2021-11-07T04:03:57.490926+00:00
2021-11-07T05:44:47.091319+00:00
7,268
false
We will do DFS in this problem. We have the condition here that we can visit a node any number of times but we shall add its value only once for that path for the calculation of its quality. \n\nSo, we would require a visited array which would keep track of the visited nodes so that we do not add its value again into t...
99
1
['Depth-First Search', 'C', 'C++']
16
maximum-path-quality-of-a-graph
[Python] Concise DFS
python-concise-dfs-by-lee215-poie
Python\npy\n def maximalPathQuality(self, A, edges, maxTime):\n G = collections.defaultdict(dict)\n for i, j, t in edges:\n G[i][j]
lee215
NORMAL
2021-11-07T04:50:19.381026+00:00
2021-11-07T04:50:19.381056+00:00
4,944
false
**Python**\n```py\n def maximalPathQuality(self, A, edges, maxTime):\n G = collections.defaultdict(dict)\n for i, j, t in edges:\n G[i][j] = G[j][i] = t\n\n def dfs(i, seen, time):\n res = sum(A[j] for j in seen) if i == 0 else 0\n for j in G[i]:\n ...
40
1
[]
9
maximum-path-quality-of-a-graph
Java DFS O(2^20) with explanation
java-dfs-o220-with-explanation-by-hdchen-saon
I spent a few minutes but I can\'t come out a workable solution until I read the constraints very carefully.\n\nAnalysis\n1. 10 <= time[j], maxTime <= 100 By th
hdchen
NORMAL
2021-11-07T05:42:59.077988+00:00
2021-11-07T05:47:03.882305+00:00
4,072
false
I spent a few minutes but I can\'t come out a workable solution until I read the constraints very carefully.\n\n**Analysis**\n1. `10 <= time[j], maxTime <= 100` By this constraint, there are at most 10 nodes in a path.\n2. There are at most `four` edges connected to each node\n3. Based on the aforementioned constraints...
25
1
['Depth-First Search', 'Java']
5
maximum-path-quality-of-a-graph
Plain DFS
plain-dfs-by-votrubac-99xt
Perhaps this problem would be more interesting if we have more nodes, or max time is not limited to 100.\n\nHere, we first build an adjacency list, and then run
votrubac
NORMAL
2021-11-07T04:02:08.079831+00:00
2021-11-07T04:08:39.112416+00:00
4,430
false
Perhaps this problem would be more interesting if we have more nodes, or max time is not limited to `100`.\n\nHere, we first build an adjacency list, and then run DFS, subtracting time and tracking the current value.\n\nThe visited array helps us determine when a node is visited for the first time. We add the node valu...
25
0
[]
5
maximum-path-quality-of-a-graph
python | BFS | 99.33% | commented
python-bfs-9933-commented-by-hanjo108-fm9i
Hello, just wrote this and wanted to checkout other\'s solution, and I couldn\'t find fast BFS solutions, so I am just sharing my code.\n\nI wonder how can I no
hanjo108
NORMAL
2022-04-20T05:50:24.474835+00:00
2022-04-20T06:01:57.193806+00:00
1,174
false
Hello, just wrote this and wanted to checkout other\'s solution, and I couldn\'t find fast BFS solutions, so I am just sharing my code.\n\nI wonder how can I not keeping copy of set every append to queue. Please **any suggest** will be appreciated\n\n**Thought process:**\n1. build undirected graph\n2. start BFS from 0 ...
15
0
['Breadth-First Search', 'Memoization', 'Python']
3
maximum-path-quality-of-a-graph
Python | Top 99.6%, 196ms | DFS + Caching + Dijkstra
python-top-996-196ms-dfs-caching-dijkstr-fkvj
Initially, we can just write a DFS. Something like this:\n\n\nclass Solution:\n def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTi
float4
NORMAL
2021-11-17T21:07:51.400099+00:00
2021-11-17T21:08:34.026575+00:00
1,453
false
Initially, we can just write a DFS. Something like this:\n\n```\nclass Solution:\n def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n neighbours = defaultdict(list)\n for v,w,t in edges:\n neighbours[v].append((w,t))\n neighbours[w].app...
13
0
['Dynamic Programming', 'Depth-First Search']
1
maximum-path-quality-of-a-graph
Java | DFS
java-dfs-by-pagalpanda-ooa6
\n\tpublic int maximalPathQuality(int[] values, int[][] edges, int maxTime) {\n List<List<int[]>> adjList = new ArrayList();\n for(int i : values)
pagalpanda
NORMAL
2021-11-16T13:39:27.528284+00:00
2021-11-16T13:39:27.528310+00:00
1,527
false
```\n\tpublic int maximalPathQuality(int[] values, int[][] edges, int maxTime) {\n List<List<int[]>> adjList = new ArrayList();\n for(int i : values) {\n adjList.add(new ArrayList());\n }\n \n for(int edge[] : edges) {\n adjList.get(edge[0]).add(new int[] {edge[1...
11
0
['Backtracking', 'Depth-First Search', 'Java']
3
maximum-path-quality-of-a-graph
Python3 || dfs w/ mask || T/S: 67% / 79%
python3-dfs-w-mask-ts-67-79-by-spaulding-e705
Here\'s the plan:\n\n1. We construct the graph with weights\n\n2. We recursively dfs-traverse the graph, and we keep track of the time and quality as we move fr
Spaulding_
NORMAL
2024-09-21T21:29:00.383574+00:00
2024-09-21T21:30:07.287834+00:00
175
false
Here\'s the plan:\n\n1. We construct the graph with weights\n\n2. We recursively dfs-traverse the graph, and we keep track of the time and quality as we move from node to node.\n3. We use a mask to determine whether we have visited the present node on this dfs; if not, we can increase the quality.\n4. If we traverse ba...
10
0
['Python3']
1
maximum-path-quality-of-a-graph
Backtracking + DFS Based Approach || C++ Clean Code
backtracking-dfs-based-approach-c-clean-sog9l
Code : \n\nclass Solution {\npublic:\n int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) {\n \n int n = valu
i_quasar
NORMAL
2021-11-21T16:25:30.629246+00:00
2021-11-25T15:26:26.757733+00:00
1,068
false
# Code : \n```\nclass Solution {\npublic:\n int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) {\n \n int n = values.size();\n \n vector<vector<pair<int, int>>> adj(n);\n \n for(auto& edge : edges) {\n adj[edge[0]].push_back({edge...
9
2
['Backtracking', 'Depth-First Search', 'Graph', 'C']
0
maximum-path-quality-of-a-graph
C++ DFS
c-dfs-by-lzl124631x-v4yj
See my latest update in repo LeetCode\n## Solution 1. DFS\n\nSince 10 <= timej, maxTime <= 100, the path at most have 10 edges. Since each node at most has 4 ed
lzl124631x
NORMAL
2021-11-07T04:01:40.785036+00:00
2021-11-09T19:43:27.649527+00:00
1,294
false
See my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n## Solution 1. DFS\n\nSince `10 <= timej, maxTime <= 100`, the path at most have `10` edges. Since each node at most has `4` edges, the maximum number of possible paths is `4^10 ~= 1e6`, so a brute force DFS should work.\n\n```cpp\n// OJ: ...
9
0
[]
2
maximum-path-quality-of-a-graph
Java dfs
java-dfs-by-shufflemix-x0z3
```java\nclass Solution {\n public class Node {\n int id;\n int value;\n List edges;\n public Node(int id, int value) {\n
shufflemix
NORMAL
2021-11-07T04:01:36.980854+00:00
2021-11-07T04:01:36.980922+00:00
1,485
false
```java\nclass Solution {\n public class Node {\n int id;\n int value;\n List<Edge> edges;\n public Node(int id, int value) {\n this.id = id;\n this.value = value;\n edges = new ArrayList<>();\n }\n }\n \n public class Edge {\n int i...
8
0
[]
1
maximum-path-quality-of-a-graph
💥💥 Beats 100% on runtime and memory [EXPLAINED]
beats-100-on-runtime-and-memory-explaine-p427
Intuition\nFinding the best route through a graph, maximizing the quality of the path while staying within a specified travel time. Each node has a value that c
r9n
NORMAL
2024-10-28T05:40:33.365555+00:00
2024-10-28T05:40:33.365613+00:00
100
false
# Intuition\nFinding the best route through a graph, maximizing the quality of the path while staying within a specified travel time. Each node has a value that contributes to the total quality, and the goal is to visit nodes strategically to collect the highest possible quality without exceeding the time limit.\n\n# A...
7
0
['Array', 'Backtracking', 'Graph', 'TypeScript']
0
maximum-path-quality-of-a-graph
[Python] DFS and BFS solution
python-dfs-and-bfs-solution-by-nightybea-23pa
DFS solution:\npython\nclass Solution:\n def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n ans = 0\n
nightybear
NORMAL
2021-11-07T06:43:52.499813+00:00
2021-11-07T06:43:52.499847+00:00
1,025
false
DFS solution:\n```python\nclass Solution:\n def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n ans = 0\n graph = collections.defaultdict(dict)\n for u, v, t in edges:\n graph[u][v] = t\n graph[v][u] = t\n \n def dfs...
5
0
['Depth-First Search', 'Breadth-First Search', 'Python', 'Python3']
1
maximum-path-quality-of-a-graph
[JavaScript] Simple DFS
javascript-simple-dfs-by-stevenkinouye-0poq
javascript\nvar maximalPathQuality = function(values, edges, maxTime) {\n const adjacencyList = values.map(() => []);\n for (const [node1, node2, time] of
stevenkinouye
NORMAL
2021-11-07T04:01:04.341916+00:00
2021-11-07T04:01:49.453579+00:00
336
false
```javascript\nvar maximalPathQuality = function(values, edges, maxTime) {\n const adjacencyList = values.map(() => []);\n for (const [node1, node2, time] of edges) {\n adjacencyList[node1].push([node2, time]);\n adjacencyList[node2].push([node1, time]);\n }\n \n const dfs = (node, quality,...
5
0
['Depth-First Search', 'JavaScript']
2
maximum-path-quality-of-a-graph
Naive DFS, backtrack, simple but my internet went off
naive-dfs-backtrack-simple-but-my-intern-y6sh
Let\'s go directly to the data size, time >= 10 and maxTime <= 100. We will let it traverse at most 10 steps from 0. \nThe sentence, at most four edges for each
ch-yyk
NORMAL
2021-11-07T04:10:23.433518+00:00
2021-11-07T08:27:00.428846+00:00
605
false
Let\'s go directly to the data size, `time >= 10` and `maxTime <= 100`. We will let it traverse at most 10 steps from 0. \nThe sentence, `at most four edges for each node`, indicate that we will have at most 4^10 steps to move in total which is\naround 10^6 to 10^7 steps. So searching in a brute force way should work o...
4
0
[]
1
maximum-path-quality-of-a-graph
python super easy to understand dfs
python-super-easy-to-understand-dfs-by-h-3qjj
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
harrychen1995
NORMAL
2023-10-30T14:47:47.267258+00:00
2023-10-30T14:47:47.267291+00:00
301
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
['Depth-First Search', 'Python3']
1
maximum-path-quality-of-a-graph
DFS || BACKTRACKING || C++ || EASY TO UNDERSTAND 60% FASTER SOLUTION
dfs-backtracking-c-easy-to-understand-60-jz38
\nclass Solution {\npublic:\n int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) {\n int n = values.size();\n
abhay_12345
NORMAL
2023-02-03T17:40:47.629027+00:00
2023-02-03T17:40:47.629062+00:00
873
false
```\nclass Solution {\npublic:\n int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) {\n int n = values.size();\n int res = values[0];\n vector<vector<pair<int,int>>> graph(n);\n for(int i=0;i<edges.size();i++)\n {\n graph[edges[i][0]].pu...
2
0
['Backtracking', 'Depth-First Search', 'Graph', 'C', 'C++']
1
maximum-path-quality-of-a-graph
[Java/C++] dfs with optimization
javac-dfs-with-optimization-by-quantumin-3jrd
A straightforward idea is to try all paths from node 0 and calculate the max path quality for paths also end with node 0.\n\nOne optimization we can add is: onc
quantuminfo
NORMAL
2021-11-07T04:00:37.384118+00:00
2021-11-07T04:00:37.384148+00:00
385
false
A straightforward idea is to try all paths from node `0` and calculate the `max path quality` for paths also end with node `0`.\n\nOne **optimization** we can add is: once we cannot return back to node `0`, we stop. The `min_time` required from any node to node `0` can be pre-computed using *Dijkstra algorithm*.\n\n**T...
3
0
[]
1
maximum-path-quality-of-a-graph
Python | Easy | Graph | Maximum Path Quality of a Graph
python-easy-graph-maximum-path-quality-o-xap7
\nsee the Successfully Accepted Submission\nPython\nclass Solution:\n def maximalPathQuality(self, values, edges, maxTime):\n n = len(values)\n
Khosiyat
NORMAL
2023-10-11T15:15:40.166161+00:00
2023-10-11T15:15:40.166182+00:00
95
false
\n[see the Successfully Accepted Submission](https://leetcode.com/submissions/detail/1071689029/)\n```Python\nclass Solution:\n def maximalPathQuality(self, values, edges, maxTime):\n n = len(values)\n adj = [[] for _ in range(n)]\n\n # Create an adjacency list to represent the graph with edges ...
2
0
['Graph', 'Python']
0
maximum-path-quality-of-a-graph
BFS 177ms Beats 100.00%of users with Python3
bfs-177ms-beats-10000of-users-with-pytho-98q7
Intuition\nGraph question - first think about using BFS\n\n# Approach\nBFS\n\n# Complexity\n\n\n# Code\n\nclass Solution:\n def maximalPathQuality(self, valu
cherrychoco
NORMAL
2023-07-18T22:42:45.050634+00:00
2023-07-21T20:32:04.853032+00:00
345
false
# Intuition\nGraph question - first think about using BFS\n\n# Approach\nBFS\n\n# Complexity\n![Screenshot 2023-07-18 at 3.40.29 PM.png](https://assets.leetcode.com/users/images/7305d8e8-92d6-4b5e-be59-a806c94ce0db_1689720115.546126.png)\n\n# Code\n```\nclass Solution:\n def maximalPathQuality(self, values: List[int...
2
0
['Breadth-First Search', 'Python', 'Python3']
0
maximum-path-quality-of-a-graph
DFS || BACKTRACKING || C++ || EASY TO UNDERSTAND 60% FASTER SOLUTION
dfs-backtracking-c-easy-to-understand-60-sg7i
\nclass Solution {\npublic:\n int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) {\n int n = values.size();\n
abhay_12345
NORMAL
2023-02-03T17:39:03.938361+00:00
2023-02-03T17:39:03.938404+00:00
627
false
```\nclass Solution {\npublic:\n int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) {\n int n = values.size();\n int res = values[0];\n vector<vector<pair<int,int>>> graph(n);\n for(int i=0;i<edges.size();i++)\n {\n graph[edges[i][0]].pu...
2
0
['Backtracking', 'Depth-First Search', 'Graph', 'C', 'C++']
0
maximum-path-quality-of-a-graph
Simple Java Backtracking Solution
simple-java-backtracking-solution-by-syc-0esl
\nclass Solution {\n int res = 0;\n\n public int maximalPathQuality(int[] values, int[][] edges, int maxTime) {\n Map<Integer, Map<Integer, Integer
sycmtic
NORMAL
2023-01-14T22:40:44.799161+00:00
2023-01-14T22:40:44.799197+00:00
194
false
```\nclass Solution {\n int res = 0;\n\n public int maximalPathQuality(int[] values, int[][] edges, int maxTime) {\n Map<Integer, Map<Integer, Integer>> map = new HashMap<>();\n int n = values.length;\n for (int i = 0; i < n; i++) map.put(i, new HashMap<>());\n for (int[] edge : edges)...
2
0
['Backtracking', 'Graph', 'Java']
0
maximum-path-quality-of-a-graph
dfs brute force
dfs-brute-force-by-beermario-lrej
python\n\'\'\'\ndfs, brute force\nO(4^n), O(4^n)\n\'\'\'\nclass Solution:\n def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime:
beermario
NORMAL
2022-08-05T09:12:28.288451+00:00
2022-08-05T09:12:28.288480+00:00
334
false
```python\n\'\'\'\ndfs, brute force\nO(4^n), O(4^n)\n\'\'\'\nclass Solution:\n def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n graph = collections.defaultdict(list)\n for u, v, time in edges:\n graph[u].append((v, time))\n graph[v].a...
2
0
['Depth-First Search']
0
maximum-path-quality-of-a-graph
Max Simplified Backtracking Cpp 👨‍💻
max-simplified-backtracking-cpp-by-conve-afrv
Why Backtracking ?\nBecause we got at most 4 children of a node and no need of worrying out infinite recursive call as your DFS tree is bounded by the maxTime.
ConvexChull
NORMAL
2022-07-07T18:29:07.891037+00:00
2022-07-07T18:31:50.058108+00:00
378
false
# Why Backtracking ?\nBecause we got at most 4 children of a node and no need of worrying out infinite recursive call as your DFS tree is bounded by the maxTime. Also look at constraints backtracking seems good bet.\n# Logic \n* Basically if you somehow were able reach to the node 0 then you should update the sum you...
2
0
['Backtracking', 'C++']
1
maximum-path-quality-of-a-graph
(C++) 2065. Maximum Path Quality of a Graph
c-2065-maximum-path-quality-of-a-graph-b-nn26
Based on @votrubac\'s solution\n\nclass Solution {\npublic:\n int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) {\n
qeetcode
NORMAL
2021-11-07T22:23:05.527911+00:00
2021-11-07T22:23:23.380609+00:00
339
false
Based on @votrubac\'s solution\n```\nclass Solution {\npublic:\n int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) {\n int n = values.size(); \n vector<vector<pair<int, int>>> graph(n); \n for (auto& x : edges) {\n graph[x[0]].emplace_back(x[1], x[2]...
2
0
['C']
1
maximum-path-quality-of-a-graph
Java DFS Solution
java-dfs-solution-by-jackyzhang98-hbzz
Classic DFS. Since we can visit a node many times, it is necessary to keep its frequency in a hashmap. The code should explains itself.\n\nclass Solution {\n
jackyzhang98
NORMAL
2021-11-07T04:29:49.906057+00:00
2021-11-07T04:29:49.906086+00:00
331
false
Classic DFS. Since we can visit a node many times, it is necessary to keep its frequency in a hashmap. The code should explains itself.\n```\nclass Solution {\n Map<Integer, List<Pair<Integer, Integer>>> map = new HashMap<>(); // source, dest, time\n int max = 0;\n int[] values;\n \n public int maximalPa...
2
0
[]
0
maximum-path-quality-of-a-graph
weak testcase
weak-testcase-by-ankitsingh9164-cba0
[0,32,43,1000]\n[[0,1,10],[1,3,10],[2,3,35],[0,2,10]]\n 49\n \n [0,32,43,1000]\n[[0,2,10],[0,1,10],[1,3,10],[2,3,35]]\n 49\n \nit\'s giving wrong ans on my code
ankitsingh9164
NORMAL
2021-11-07T04:03:54.359713+00:00
2021-11-07T04:05:04.197597+00:00
211
false
[0,32,43,1000]\n[[0,1,10],[1,3,10],[2,3,35],[0,2,10]]\n 49\n \n [0,32,43,1000]\n[[0,2,10],[0,1,10],[1,3,10],[2,3,35]]\n 49\n \nit\'s giving wrong ans on my code but still it passed internal testcase\n\n`\n ArrayList<int[]> tree[];\n\t \n\t public int maximalPathQuality(int[] values, int[][] edges, int maxTime) {\n ...
2
0
[]
1
maximum-path-quality-of-a-graph
[Python3] iterative dfs
python3-iterative-dfs-by-ye15-0efr
Please check out this commit for solutions of weekly 266. \n\n\nclass Solution:\n def maximalPathQuality(self, values: List[int], edges: List[List[int]], max
ye15
NORMAL
2021-11-07T04:02:00.111791+00:00
2021-11-07T05:11:25.635188+00:00
566
false
Please check out this [commit](https://github.com/gaosanyong/leetcode/commit/6b6e6b9115d2b659e68dcf3ea8e21befefaae16c) for solutions of weekly 266. \n\n```\nclass Solution:\n def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n graph = [[] for _ in values]\n f...
2
0
['Python3']
1
maximum-path-quality-of-a-graph
Simple C Solution using DFS
simple-c-solution-using-dfs-by-sahnasere-zroq
Code\n\n#define max(a,b) (a > b ? a : b)\n\nstruct ht_map{\n struct ht_map* next;\n int adj;\n int time;\n};\n\nvoid find_path_dfs(struct ht_map** time
sahnaseredini
NORMAL
2024-04-06T18:47:23.935318+00:00
2024-04-06T18:47:23.935340+00:00
14
false
# Code\n```\n#define max(a,b) (a > b ? a : b)\n\nstruct ht_map{\n struct ht_map* next;\n int adj;\n int time;\n};\n\nvoid find_path_dfs(struct ht_map** times, int* values, int size, int* visited, int* out, int max, int i, int time, int max_time){\n if(time > max_time)\n return;\n if(visited[i] == ...
1
0
['Array', 'Backtracking', 'Graph', 'C']
0
maximum-path-quality-of-a-graph
Beats 95%, DFS with Memoization, (bitwise operator explainer)
beats-95-dfs-with-memoization-bitwise-op-jaje
Intuition\nSince you\'re allowed to revisit nodes, you can\'t use previously visited nodes to avoid loops, instead you have to use the time_left to avoid loops,
Yowfat
NORMAL
2024-04-02T19:37:06.884363+00:00
2024-04-02T19:58:51.529760+00:00
56
false
# Intuition\nSince you\'re allowed to revisit nodes, you can\'t use previously visited nodes to avoid loops, instead you have to use the time_left to avoid loops,\nhowever, if you\'ve previously visited this node, you can\'t add it\'s value to the answer, so you still need to keep track of previously visited\n\n# Appro...
1
0
['Python3']
1
maximum-path-quality-of-a-graph
Very easy DFS code | Beginner friendly
very-easy-dfs-code-beginner-friendly-by-y1q1b
\nclass Solution {\npublic:\n int maxi=-1;\n void solve(unordered_map<int,vector<pair<int,int>>> &m,vector<int> &temp, int node,int t,bool &f,vector<int>&
looserboy
NORMAL
2023-10-28T06:49:54.738616+00:00
2023-10-28T06:49:54.738648+00:00
802
false
```\nclass Solution {\npublic:\n int maxi=-1;\n void solve(unordered_map<int,vector<pair<int,int>>> &m,vector<int> &temp, int node,int t,bool &f,vector<int>& v){\n if(t<0) return;\n if(node==0&&f&&t>=0){\n int tp=0;\n vector<int> vis(v.size(),0);\n for(auto it: temp)...
1
0
['Backtracking', 'Depth-First Search', 'Graph', 'Recursion', 'C']
1
maximum-path-quality-of-a-graph
Simple easy to understand
simple-easy-to-understand-by-raj_tirtha-7s1j
Code\n\nclass Solution {\npublic:\n int ans=0;\n void dfs(int node,int maxTime,vector<int> &vis,vector<vector<pair<int,int>>> &adj,int &sum,vector<int> &v
raj_tirtha
NORMAL
2023-08-24T05:07:00.896643+00:00
2023-08-24T05:07:00.896662+00:00
77
false
# Code\n```\nclass Solution {\npublic:\n int ans=0;\n void dfs(int node,int maxTime,vector<int> &vis,vector<vector<pair<int,int>>> &adj,int &sum,vector<int> &values){\n vis[node]++;\n if(vis[node]==1) sum+=values[node];\n if(node==0) ans=max(ans,sum);\n for(auto it:adj[node]){\n ...
1
0
['C++']
0
maximum-path-quality-of-a-graph
(Here's my Journey) Beats 80%
heres-my-journey-beats-80-by-pathetik_co-u53r
Intuition\n Describe your first thoughts on how to solve this problem. \n\nThese kinds of problem are not very common , as normally the composer tries to make a
pathetik_coder
NORMAL
2023-05-01T21:15:01.340670+00:00
2023-05-01T21:15:01.340725+00:00
58
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nThese kinds of problem are not very common , as normally the composer tries to make a problem interesting by mixing the use of differnt algorithm or making a different version of algorithm .\nBut in this question It was just constraints...
1
0
['C++']
0
maximum-path-quality-of-a-graph
Python BackTrack
python-backtrack-by-zzjoshua-001n
\nclass Solution:\n def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n \n ans, res = values[0], 0\
zzjoshua
NORMAL
2022-11-15T21:28:35.574986+00:00
2022-11-15T21:28:35.575010+00:00
78
false
```\nclass Solution:\n def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n \n ans, res = values[0], 0\n nodes = defaultdict(list)\n for x,y,c in edges:\n nodes[x].append((y, c))\n nodes[y].append((x, c))\n\n def back...
1
0
['Backtracking', 'Python']
0
maximum-path-quality-of-a-graph
[Python] Commented DFS Solution | Concise
python-commented-dfs-solution-concise-by-1mw7
\nclass Solution:\n def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n # Creating an adjaceny list \n
ParthRohilla
NORMAL
2022-11-09T12:42:55.350167+00:00
2022-11-09T12:42:55.350199+00:00
366
false
```\nclass Solution:\n def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n # Creating an adjaceny list \n G = defaultdict(list)\n for u,v,w in edges:\n G[u].append([v,w])\n G[v].append([u,w])\n \n def dfs(current...
1
0
['Depth-First Search', 'Python']
1
maximum-path-quality-of-a-graph
BFS
bfs-by-pranvpable-pgv7
\nclass Solution:\n def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n graph = defaultdict(list)\n
pranvpable
NORMAL
2022-11-03T14:03:14.262921+00:00
2022-11-03T14:03:14.262961+00:00
91
false
```\nclass Solution:\n def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n graph = defaultdict(list)\n \n for u,v,time in edges:\n graph[u].append([v,time])\n graph[v].append([u,time])\n \n seen = set()\n ...
1
0
['Breadth-First Search']
0
maximum-path-quality-of-a-graph
[C++] Super Short Solution !!!
c-super-short-solution-by-kylewzk-ze8h
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
kylewzk
NORMAL
2022-10-08T05:48:32.931058+00:00
2022-10-08T05:48:32.931104+00:00
67
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)$$ --...
1
0
['C++']
0
maximum-path-quality-of-a-graph
[Python 3] DFS+BackTrack
python-3-dfsbacktrack-by-gabhay-heoz
\tclass Solution:\n\t\tdef maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n\t\t\tn=len(values)\n\t\t\tG=[[] for _ in
gabhay
NORMAL
2022-08-02T12:08:01.888539+00:00
2022-08-02T12:10:56.953097+00:00
138
false
\tclass Solution:\n\t\tdef maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n\t\t\tn=len(values)\n\t\t\tG=[[] for _ in range(n)]\n\t\t\tfor u,v,t in edges:\n\t\t\t\tG[u].append([v,t])\n\t\t\t\tG[v].append([u,t])\n\t\t\tself.res=0\n\t\t\tdef dfs(node,time,path,val):\n\t\t\t\tif n...
1
0
[]
0
maximum-path-quality-of-a-graph
[Python] DFS Recursive
python-dfs-recursive-by-happysde-apu1
\nclass Solution:\n \n def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n d = defaultdict(list)\n
happysde
NORMAL
2022-06-27T22:15:53.469773+00:00
2022-06-27T22:15:53.469811+00:00
152
false
```\nclass Solution:\n \n def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n d = defaultdict(list)\n n = len(values)\n \n for edge in edges:\n d[edge[0]].append([edge[1], edge[2]])\n d[edge[1]].append([edge[0], edge[2]]...
1
0
['Depth-First Search', 'Recursion', 'Python3']
1
maximum-path-quality-of-a-graph
Python || DFS with just 3 Dimensions || Using Node Traversal Count to stop
python-dfs-with-just-3-dimensions-using-2as69
Its mentioned that : There are at most four edges connected to each node.\nSo I have implemented a map to store how many times a node has been traversed.\nI bre
subin_nair
NORMAL
2022-06-16T13:08:50.525978+00:00
2022-06-16T19:39:10.126970+00:00
187
false
Its mentioned that : `There are at most four edges connected to each node.`\nSo I have implemented a map to store how many times a `node` has been traversed.\nI break the `dfs` process when the a node has been traversed for the `5th` time. \nThis is because **`nodes should be traversed back and forth for a max of 4 tim...
1
0
['Depth-First Search', 'Python']
1
maximum-path-quality-of-a-graph
C++ || DFS || Easy to understand
c-dfs-easy-to-understand-by-iota_2010-0nbe
\nclass Solution {\npublic:\n int rec(vector<int>& values, vector<vector<pair<int,int>>>& vec, int maxt,int x)\n {\n int ans=INT_MIN;\n if(x
iota_2010
NORMAL
2022-05-25T21:45:25.538870+00:00
2022-05-25T21:45:25.538907+00:00
119
false
```\nclass Solution {\npublic:\n int rec(vector<int>& values, vector<vector<pair<int,int>>>& vec, int maxt,int x)\n {\n int ans=INT_MIN;\n if(x==0)\n ans=0;\n for(int i=0;i<vec[x].size();i++)\n {\n int a=vec[x][i].first,b=vec[x][i].second;\n if(b<=maxt)...
1
0
['Backtracking', 'Depth-First Search', 'C', 'C++']
0
maximum-path-quality-of-a-graph
Python 🐍 DFS recursive with cache and frozen set
python-dfs-recursive-with-cache-and-froz-2fg6
Idea inspired from @float4, using cashe to speed up the dfs so it\'s do any unnecessary recalucations that were made before, however as cache doesn\'t work with
injysarhan
NORMAL
2022-02-02T09:08:41.215088+00:00
2022-02-02T09:08:41.215121+00:00
242
false
Idea inspired from @float4, using cashe to speed up the dfs so it\'s do any unnecessary recalucations that were made before, however as cache doesn\'t work with sets and maps, had to use a immuatble version of set --> [frozenset](https://www.programiz.com/python-programming/methods/built-in/frozenset) \n\n```\nclass So...
1
0
['Depth-First Search', 'Python']
0
maximum-path-quality-of-a-graph
DFS || C++ || Easy To Understand
dfs-c-easy-to-understand-by-vineetjai-a93a
\nclass Solution {\n vector<vector<pair<int,int>>> grp;\n int ans;\n void dfs(int u,int cost,int gain,vector<int>& values,vector<int> &vis){\n i
vineetjai
NORMAL
2021-12-29T07:21:14.101035+00:00
2021-12-29T07:21:14.101077+00:00
359
false
```\nclass Solution {\n vector<vector<pair<int,int>>> grp;\n int ans;\n void dfs(int u,int cost,int gain,vector<int>& values,vector<int> &vis){\n if(!vis[u]) gain+=values[u];\n if(u==0) ans=max(ans,gain);\n vis[u]++; \n for(auto j:grp[u])\n if(j.second<=cost) dfs(j.fir...
1
0
['Depth-First Search', 'C']
1
maximum-path-quality-of-a-graph
[Python] memoized DFS
python-memoized-dfs-by-mars_congressiona-kcna
Like many other solutions, in order to memoize the backtracking, we can use a bitmask, i.e. an int holding (2**n)-1 bits. I write out as functions what we need
Mars_Congressional_Republic
NORMAL
2021-12-04T20:58:23.981319+00:00
2021-12-04T20:58:23.981349+00:00
167
false
Like many other solutions, in order to memoize the backtracking, we can use a bitmask, i.e. an int holding (2**n)-1 bits. I write out as functions what we need to do to a bitmask in order to run the DFS successfully\n\n```\nclass Solution:\n def maximalPathQuality(self, values: List[int], edges: List[List[int]], max...
1
1
[]
0
maximum-path-quality-of-a-graph
c++ dfs
c-dfs-by-nitesh_nitp-oz8s
long long int max(long long int ans,long long int sum)\n{\n return ans>=sum?ans:sum;\n}\nvoid fun(int a,vector>>& g,vector& values,int maxTime,long long int
nitesh_nitp
NORMAL
2021-11-12T13:03:21.041018+00:00
2021-11-12T13:03:21.041051+00:00
152
false
long long int max(long long int ans,long long int sum)\n{\n return ans>=sum?ans:sum;\n}\nvoid fun(int a,vector<vector<pair<int,int>>>& g,vector<int>& values,int maxTime,long long int & sum,int & time,long long int & ans)\n{\n if(a==0) { ans=max(ans,sum); }\n for(auto x : g[a])\n {\n if((time+x.seco...
1
0
[]
0
maximum-path-quality-of-a-graph
[Scala] Functional no vars DFS solution
scala-functional-no-vars-dfs-solution-by-ul7q
\n def maximalPathQuality(values: Array[Int], edges: Array[Array[Int]], maxTime: Int): Int = {\n val adjList = edges.foldLeft(Map.empty[Int, Seq[(Int, Int)]
cosminci
NORMAL
2021-11-11T15:38:12.079567+00:00
2022-03-02T21:29:37.031373+00:00
55
false
```\n def maximalPathQuality(values: Array[Int], edges: Array[Array[Int]], maxTime: Int): Int = {\n val adjList = edges.foldLeft(Map.empty[Int, Seq[(Int, Int)]].withDefaultValue(Seq.empty)) {\n case (adj, Array(n1, n2, cost)) =>\n adj\n .updated(n1, adj(n1) :+ (n2, cost))\n .updated(n2...
1
0
['Depth-First Search']
0
maximum-path-quality-of-a-graph
[JAVA] Modified DFS + visited
java-modified-dfs-visited-by-rico_13-vcwj
```\nclass Solution {\n int maxq=0;\n public void helper(List[] graph ,int si,int ql,int vis[],int time,int []values){\n if(time<0) return;\n
Rico_13
NORMAL
2021-11-07T20:57:47.808538+00:00
2021-11-07T20:57:47.808584+00:00
125
false
```\nclass Solution {\n int maxq=0;\n public void helper(List<int[]>[] graph ,int si,int ql,int vis[],int time,int []values){\n if(time<0) return;\n vis[si]++;\n if(vis[si]==1) ql+=values[si];\n \n if(si==0 && time>=0) maxq=Math.max(maxq,ql);\n \n \n \n ...
1
1
['Backtracking', 'Java']
0
maximum-path-quality-of-a-graph
Never use Map if you can use array in Java on LeetCode
never-use-map-if-you-can-use-array-in-ja-4a83
Just backtracking solution for Q4, but I use Map<Integer, Integer> visited, then I get a TLE, after the contest, I tried int[] visited, and AC.\n\n\nTLE code\n\
toffeelu
NORMAL
2021-11-07T07:10:10.999421+00:00
2021-11-07T07:10:31.533575+00:00
141
false
Just backtracking solution for Q4, but I use `Map<Integer, Integer> visited`, then I get a TLE, after the contest, I tried `int[] visited`, and AC.\n\n\nTLE code\n```\nclass Solution {\n public int maximalPathQuality(int[] values, int[][] edges, int maxTime) {\n int n = values.length;\n Map<Integer, Ma...
1
0
[]
3
maximum-path-quality-of-a-graph
Java DFS solution
java-dfs-solution-by-nehakothari-v7sw
Inspiration from @votrubac \'s Plain DFS solution :\nhttps://leetcode.com/problems/maximum-path-quality-of-a-graph/discuss/1563744/Plain-DFS\n\n\nclass Solution
nehakothari
NORMAL
2021-11-07T06:11:18.317857+00:00
2021-11-07T06:11:18.317889+00:00
102
false
Inspiration from @votrubac \'s Plain DFS solution :\nhttps://leetcode.com/problems/maximum-path-quality-of-a-graph/discuss/1563744/Plain-DFS\n\n```\nclass Solution {\n \n int result = 0;\n List<List<int[]>> graph = new ArrayList<>();\n int[] values;\n int[] visited;\n public int maximalPathQuality(int...
1
0
[]
0
maximum-path-quality-of-a-graph
Java | backtracking | Concise | O(4^10)
java-backtracking-concise-o410-by-tyro-e4nz
Backtracking with the length of the paths limited to 10 at most. The branch factor is 4. So Time O(4^10).\n\n\nclass Solution {\n Map<Integer, Map<Integer, I
tyro
NORMAL
2021-11-07T05:42:35.216046+00:00
2021-11-07T05:51:54.754014+00:00
349
false
Backtracking with the length of the paths limited to 10 at most. The branch factor is 4. So Time O(4^10).\n\n```\nclass Solution {\n Map<Integer, Map<Integer, Integer> > g = new HashMap();\n int res = 0;\n int[] values;\n public int maximalPathQuality(int[] values, int[][] edges, int maxTime) {\n thi...
1
0
['Backtracking', 'Depth-First Search', 'Java']
0
maximum-path-quality-of-a-graph
[C++] DFS
c-dfs-by-ericyxing-hvnn
Logical Thinking\nSince each node\'s value can be added only once, we\'d better use Depth-First Search to solve this problem. So we start from node 0, and try a
EricYXing
NORMAL
2021-11-07T05:14:26.718260+00:00
2021-11-07T05:14:26.718304+00:00
176
false
<strong>Logical Thinking</strong>\n<p>Since each node\'s value can be added only once, we\'d better use <strong>Depth-First Search</strong> to solve this problem. So we start from node <code>0</code>, and try all possible paths (edges can be used more than once). Each time we come to a new node which is not counted bef...
1
0
['Depth-First Search', 'C']
0
maximum-path-quality-of-a-graph
Easy understanding java code (Plain DFS)
easy-understanding-java-code-plain-dfs-b-dy1z
\nclass Solution {\n public int maximalPathQuality(int[] values, int[][] edges, int maxTime) {\n int n = values.length;\n int[] res = new int[]
Ramsey0704
NORMAL
2021-11-07T04:50:25.970236+00:00
2021-11-07T04:50:25.970266+00:00
112
false
```\nclass Solution {\n public int maximalPathQuality(int[] values, int[][] edges, int maxTime) {\n int n = values.length;\n int[] res = new int[]{Integer.MIN_VALUE};\n List<List<int[]>> graph = buildGraph(n, edges);\n Set<Integer> visited = new HashSet<>();\n visited.add(0);\n ...
1
0
[]
0
maximum-path-quality-of-a-graph
I have one conjecture, need some1 to prove (for optimal pruning during DFS search)
i-have-one-conjecture-need-some1-to-prov-mi79
Hi, my statement is that:\n\n\n"This path(or at least one of the best path) won\'t contain duplicate directional edge. "\n\n\nI mean it can contain 0->1 and 1-
a_pinterest_employee
NORMAL
2021-11-07T04:11:34.747658+00:00
2021-11-10T20:14:04.554672+00:00
213
false
Hi, my statement is that:\n\n```\n"This path(or at least one of the best path) won\'t contain duplicate directional edge. "\n```\n\nI mean it can contain 0->1 and 1->0, but it won\'t contian two 0->1.
1
0
[]
4
maximum-path-quality-of-a-graph
Python Simple Dijkstra
python-simple-dijkstra-by-kodewithklossy-sswg
\nclass Solution:\n def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n graph = defaultdict(dict) # dict o
kodewithklossy
NORMAL
2021-11-07T04:07:33.028458+00:00
2021-11-07T04:07:33.028497+00:00
260
false
```\nclass Solution:\n def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n graph = defaultdict(dict) # dict of dict to store weights\n pq = []\n res = 0\n\n heapq.heappush(pq, (-values[0], 0, 0, {0})) # quality, time, index, nodes\n\n for...
1
0
[]
1
maximum-path-quality-of-a-graph
[Python] simple brute-force DFS | O(4^10)
python-simple-brute-force-dfs-o410-by-go-la9n
We can just DFS / backtrack the graph starting from the initial node in the simplistic way. Cyclic paths are allowed because visited nodes are not filtered out
gowe
NORMAL
2021-11-07T04:00:55.849087+00:00
2021-11-07T04:00:55.849148+00:00
187
false
We can just DFS / backtrack the graph starting from the initial node in the simplistic way. Cyclic paths are allowed because visited nodes are not filtered out as they are in typical graph traversal. There won\'t be stack overflow since the constraints on input are pretty small. \n\n> There are *at most four* edges con...
1
0
[]
0
maximum-path-quality-of-a-graph
Java DFS - key is to flip the newVisit
java-dfs-key-is-to-flip-the-newvisit-by-bus82
IntuitionApproachComplexity Time complexity: Space complexity: Code
yyy0755
NORMAL
2025-03-25T06:26:41.341232+00:00
2025-03-25T06:26:41.341232+00:00
8
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Java']
0
maximum-path-quality-of-a-graph
Python3 - BFS Solution - Beats 98%
python3-bfs-solution-beats-98-by-aaron_m-tx0b
Code
aaron_mathis
NORMAL
2025-02-23T18:37:40.415245+00:00
2025-02-23T18:37:40.415245+00:00
7
false
# Code ```python3 [] class Solution: def maximalPathQuality(self, nodeValues: List[int], edges: List[List[int]], maxAllowedTime: int) -> int: # Build the adjacency list representation of the graph graph = defaultdict(list) for startNode, endNode, travelTime in edges: graph[startN...
0
0
['Array', 'Breadth-First Search', 'Graph', 'Python3']
0
maximum-path-quality-of-a-graph
Working BFS.
working-bfs-by-woekspace-v4k7
IntuitionApproachComplexity Time complexity: Space complexity: Code
woekspace
NORMAL
2025-01-24T08:31:45.733601+00:00
2025-01-24T08:31:45.733601+00:00
6
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['C++']
0
maximum-path-quality-of-a-graph
Python Hard
python-hard-by-lucasschnee-r2lk
null
lucasschnee
NORMAL
2025-01-17T16:03:02.929882+00:00
2025-01-17T16:03:02.929882+00:00
17
false
```python3 [] class Solution: def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int: ''' 2000 edges There are at most four edges connected to each node. we want to maximize score score is sum of unique nodes simple dp ...
0
0
['Python3']
0
maximum-path-quality-of-a-graph
2065. Maximum Path Quality of a Graph
2065-maximum-path-quality-of-a-graph-by-5taqm
IntuitionApproachComplexity Time complexity: Space complexity: Code
G8xd0QPqTy
NORMAL
2025-01-17T15:47:17.521104+00:00
2025-01-17T15:47:17.521104+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['Python3']
0
maximum-path-quality-of-a-graph
Java DFS | Just dont add cycle check that we do in regular DFS
java-dfs-just-dont-add-cycle-check-that-i270z
IntuitionApproachComplexity Time complexity: O(V+E) Space complexity: Code
saptarshichatterjee1
NORMAL
2024-12-17T15:11:49.389569+00:00
2024-12-17T15:11:49.389569+00:00
13
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(V+E)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n...
0
0
['Java']
0
maximum-path-quality-of-a-graph
Maximum Path Quality of a Graph
maximum-path-quality-of-a-graph-by-naeem-2sbh
IntuitionApproachit's pretty much straightforward. i am keeping track of frequency of node in my path in the visited array. keeping track of time while doing DF
Naeem_ABD
NORMAL
2024-12-17T06:57:33.214146+00:00
2024-12-17T06:57:33.214146+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. -->\nit\'s pretty much straightforward. i am keeping track of frequency of node in my path in the visited array. keeping track of time while doing DFS. calling recursive ca...
0
0
['C++']
0
maximum-path-quality-of-a-graph
✅BFS + BitMagic || python
bfs-bitmagic-python-by-darkenigma-r93k
Code
darkenigma
NORMAL
2024-12-16T00:56:29.914721+00:00
2024-12-16T00:56:29.914721+00:00
4
false
\n# Code\n```python3 []\nclass Solution:\n def maximalPathQuality(self, values: List[int], edges: List[List[int]], maxTime: int) -> int:\n n=len(values)\n gra=[[] for i in range(n)]\n for a,b,time in edges:\n gra[a].append([b,time])\n gra[b].append([a,time])\n\n q=de...
0
0
['Array', 'Graph', 'Python3']
0
maximum-path-quality-of-a-graph
Dijskra (beat 95%)
dijskra-beat-95-by-fredzqm-uddt
Code\njava []\nclass Solution {\n public int maximalPathQuality(int[] values, int[][] edges, int maxTime) {\n Node[] nodes = new Node[values.length];\
fredzqm
NORMAL
2024-12-09T00:38:28.586735+00:00
2024-12-09T00:38:28.586773+00:00
18
false
# Code\n```java []\nclass Solution {\n public int maximalPathQuality(int[] values, int[][] edges, int maxTime) {\n Node[] nodes = new Node[values.length];\n for (int i = 0; i < values.length; i++) {\n nodes[i] = new Node(i, values[i]);\n }\n for (int[] e: edges) {\n ...
0
0
['Java']
0
maximum-path-quality-of-a-graph
maximum-path-quality-of-a-graph - Java Solution
maximum-path-quality-of-a-graph-java-sol-m2g9
\n\n# Code\njava []\nclass Solution {\n HashMap<Integer,List<int[]>> graph;\n int result=0;\n public int maximalPathQuality(int[] values, int[][] edges
himashusharma
NORMAL
2024-11-14T07:29:54.068179+00:00
2024-11-14T07:29:54.068220+00:00
9
false
\n\n# Code\n```java []\nclass Solution {\n HashMap<Integer,List<int[]>> graph;\n int result=0;\n public int maximalPathQuality(int[] values, int[][] edges, int maxTime) {\n graph=new HashMap<>();\n for(int[] i:edges){\n graph.computeIfAbsent(i[0],k->new ArrayList<>()).add(new int[]{i[1...
0
0
['Array', 'Backtracking', 'Graph', 'Java']
0
maximum-path-quality-of-a-graph
Python (Simple Backtracking)
python-simple-backtracking-by-rnotappl-nn29
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
rnotappl
NORMAL
2024-11-01T16:51:43.856798+00:00
2024-11-01T16:51:43.856840+00:00
14
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['Python3']
0
maximum-path-quality-of-a-graph
2065. Maximum Path Quality of a Graph.cpp
2065-maximum-path-quality-of-a-graphcpp-cx9u6
Code\n\nclass Solution {\npublic:\n int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) {\n int n = values.size(); \n
202021ganesh
NORMAL
2024-10-29T10:54:48.933522+00:00
2024-10-29T10:54:48.933540+00:00
2
false
**Code**\n```\nclass Solution {\npublic:\n int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) {\n int n = values.size(); \n vector<vector<pair<int, int>>> graph(n); \n for (auto& x : edges) {\n graph[x[0]].emplace_back(x[1], x[2]); \n graph...
0
0
['C']
0
maximum-path-quality-of-a-graph
Python3 Djikstra+Backtracking (For somewhat tighter constraints)
python3-djikstrabacktracking-for-somewha-dos4
Use Djikstra to find the shortest distance to come back to 0 for every node. This shortest distance will be used as a pruning/terminating condition while backtr
vintersosa
NORMAL
2024-10-08T06:50:39.158988+00:00
2024-10-08T06:50:39.159031+00:00
3
false
Use Djikstra to find the shortest distance to come back to 0 for every node. This shortest distance will be used as a pruning/terminating condition while backtracking.\n\n\nTC: 4^maxTime (though will be reduced due to pruning and for this question it will always be less than 4^10 as maxTime is 100 at maximum and every ...
0
0
['Python3']
0
maximum-path-quality-of-a-graph
C# DFS with Backtracking Solution
c-dfs-with-backtracking-solution-by-getr-m3sd
Intuition\n- Describe your first thoughts on how to solve this problem. Graph Traversal: Since the problem involves finding paths from node 0 back to node 0, a
GetRid
NORMAL
2024-10-02T15:41:32.388229+00:00
2024-10-02T15:41:32.388268+00:00
10
false
# Intuition\n- <!-- Describe your first thoughts on how to solve this problem. -->Graph Traversal: Since the problem involves finding paths from node 0 back to node 0, a natural way to explore the graph is using DFS. DFS allows us to explore all possible paths while keeping track of the time taken.\n\n- Maximizing Qual...
0
0
['Array', 'Backtracking', 'Graph', 'C#']
0
maximum-path-quality-of-a-graph
Java BFS with DP
java-bfs-with-dp-by-shandlikamal248-mqcx
Intuition\nBFS with dp\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.
shandlikamal248
NORMAL
2024-09-18T16:52:24.458864+00:00
2024-09-18T16:52:24.458897+00:00
12
false
# Intuition\nBFS with dp\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)$$ -->\n\n# Code\n```java []\nclass Solution {\n class Nod...
0
0
['Java']
0
maximum-path-quality-of-a-graph
Easy CPP Solution Beats 90% users
easy-cpp-solution-beats-90-users-by-king-nzt3
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
kingsenior
NORMAL
2024-09-16T20:58:13.065718+00:00
2024-09-16T20:58:13.065741+00:00
1
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
['C++']
0
maximum-path-quality-of-a-graph
C++ Solution
c-solution-by-mayank71203-13p2
Code\ncpp []\nclass Solution {\nprivate:\n int n,res, maxiTime;\npublic:\n void dfs(vector<int>& values, vector<vector<pair<int,int>>>& graph,int node, in
mayank71203
NORMAL
2024-09-10T21:01:50.626224+00:00
2024-09-10T21:01:50.626261+00:00
4
false
# Code\n```cpp []\nclass Solution {\nprivate:\n int n,res, maxiTime;\npublic:\n void dfs(vector<int>& values, vector<vector<pair<int,int>>>& graph,int node, int time, int curr){\n if(time > maxiTime){\n return ;\n }\n\n int oldValue = values[node];\n curr += oldValue;\n ...
0
0
['C++']
0
maximum-path-quality-of-a-graph
Maximum Path Quality of a Graph
maximum-path-quality-of-a-graph-by-shalu-prc1
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
Shaludroid
NORMAL
2024-09-09T19:36:16.292932+00:00
2024-09-09T19:36:16.292969+00:00
13
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
maximum-path-quality-of-a-graph
Backtracking in Graph with Comments
backtracking-in-graph-with-comments-by-s-7ihp
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
stalebii
NORMAL
2024-09-08T18:20:24.855500+00:00
2024-09-08T18:20:24.855539+00:00
16
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: O(n * (2^n))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here...
0
0
['Array', 'Backtracking', 'Depth-First Search', 'Graph', 'Recursion', 'Python', 'Python3']
0
maximum-path-quality-of-a-graph
Easy DFS solution
easy-dfs-solution-by-vikash_kumar_dsa2-0q4b
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
vikash_kumar_dsa2
NORMAL
2024-09-01T14:51:07.110806+00:00
2024-09-01T14:51:07.110831+00:00
6
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
0
0
['C++']
0
maximum-path-quality-of-a-graph
The only Difficulty you might face.
the-only-difficulty-you-might-face-by-pa-mxfv
Intuition\nThe only difficulty you might face in this question is on deciding how to maintain the visited state. \n\n# Code\ncpp []\nclass Solution {\npublic:\n
payadikishan
NORMAL
2024-08-28T01:13:47.269756+00:00
2024-08-28T01:13:47.269786+00:00
39
false
# Intuition\nThe only difficulty you might face in this question is on deciding how to maintain the visited state. \n\n# Code\n```cpp []\nclass Solution {\npublic:\n int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) {\n int n = values.size();\n int res = values[0];\n ...
0
0
['C++']
1
maximum-path-quality-of-a-graph
Python 3: FT 94%: Modified Dijkstra, Hard to Solve, but Surprisingly Straightforward To Code Up
python-3-ft-94-modified-dijkstra-hard-to-ichv
Intuition\n\nThe tough part of this problem IMO is convincing yourself that whatever algorithm you come up with won\'t give you TLE.\n\nA big part of that is to
biggestchungus
NORMAL
2024-08-25T05:41:20.741356+00:00
2024-08-25T05:42:26.896084+00:00
13
false
# Intuition\n\nThe tough part of this problem IMO is convincing yourself that whatever algorithm you come up with won\'t give you TLE.\n\nA big part of that is to notice that\n* the minimum `time` between any two edges is `10` or more\n* and the `maxTime` is at most 100\n* therefore each path can have at most 11 nodes ...
0
0
['Python3']
0