Parallel Courses III - Leetcode 2050 - Python
VloĆŸit
- Äas pĆidĂĄn 24. 07. 2024
- đ neetcode.io/ - A better way to prepare for Coding Interviews
đ„· Discord: / discord
đŠ Twitter: / neetcode1
đź Support the channel: / neetcode
â BLIND-75 PLAYLIST: âą Two Sum - Leetcode 1 -...
đĄ DYNAMIC PROGRAMMING PLAYLIST: âą House Robber - Leetco...
Problem Link: leetcode.com/problems/paralle...
0:00 - Read the problem
0:30 - Drawing Explanation
6:50 - Coding Explanation
leetcode 2050
#neetcode #leetcode #python
Along with daily problems it will be great if you solved the weekly problems as well. Like to treat your solutions as benchmark !!
Was waiting for your solution. Thank you
Awesome !!! Thank you !! You may want to consider shifting to the old UI in leetcode for those questions where the diagrams are not clear.
that is an issue due to using dark mode and not the UI doe
Dude I was able to solve this problem on my own. Came here to check if my solution is as efficient as yours. I would like to thank you for this. I always refer to your solution. Thanks a lot.
what language do you use?
@@bablugupta2119 Python
Thank you for all the explanations making it easier to understand. Can you please make a video on Parallel Courses II?
Here if the node 5 is reached from node 1 and cached the node 5 will return the cached value when trying to reach from node 2 right so how maxtime is updated here
That's some motivation now.
did the same thing in cpp got tle insted lol:(
Here is a javascript solution using DFS & DP
var minimumTime = function(n, relations, time) {
const graph = Array(n+1).fill().map(() => [])
const memo = {}
let ans = 0
for(const [prev,next] of relations){
graph[prev].push(next)
}
const dfs = (node) => {
if(memo[node]) return memo[node]
let max_month = 0
for(const adj of graph[node]){
max_month = Math.max(max_month, dfs(adj))
}
memo[node] = max_month + time[node-1]
return memo[node]
}
for(let node = 1; node
Can anyone tell me whats this software for take notes?
I use paint3d (windows only)
its a simple toposort question.
Ayooo, first???
Can someone tell me java equivalent code?
Here it is, mate!
class Solution {
public int minimumTime(int n, int[][] relations, int[] time) {
ArrayList adj = new ArrayList(n);
for (int i = 0; i < n; i++) {
adj.add(new ArrayList());
}
for(int[] el : relations) {
adj.get(el[0] - 1).add(el[1] - 1);
}
int[] mxtime = new int[n];
int ans = 0;
for(int i = 0; i < n; i++) {
ans = Math.max(ans, dfs(i, adj, time, mxtime));
}
return ans;
}
public int dfs(int curr, ArrayList adj, int[] time, int[] mxtime) {
if(mxtime[curr] != 0) {
return mxtime[curr];
}
int result = time[curr];
for(int i : adj.get(curr)) {
result = Math.max(result, time[curr] + dfs(i, adj, time, mxtime));
}
mxtime[curr] = result;
return result;
}
}