FIND ALL RECIPES FROM GIVEN SUPPLIES | LEETCODE 2115 | PYTHON TOPOLOGICAL SORT SOLUTION

  Рет қаралды 4,489

Cracking FAANG

Cracking FAANG

Күн бұрын

Пікірлер: 14
@aishwariyaaish8305
@aishwariyaaish8305 Жыл бұрын
crazily addicted to all your videos, other short videos outside the channel need to be played multiple times to understand fully but every videos in your playlist just require O(1) time to be played to understand and code. Thank you is really underestimated word for this video Thanks Cracking Faang channel :)
@crackfaang
@crackfaang Жыл бұрын
Thanks for the kind words and glad you are enjoying the content!
@iamnoob7593
@iamnoob7593 9 күн бұрын
Superb thanks a lot man. I coded this in java
@victoronofiok520
@victoronofiok520 Жыл бұрын
thanks for this. You don't need the extra set to lookup recipes though since you already have it in your indegree dictionary and its also o(1) to lookup. what do you think?
@vickydas6480
@vickydas6480 8 ай бұрын
Yes 👍
@samuel2221
@samuel2221 Жыл бұрын
Thank you for the solution. Could you please make a video for these two problems? 1. Maximum Number of Visible Points (1610) and, 2. Range Module (715)
@crackfaang
@crackfaang Жыл бұрын
I just made the video for Range Module and I can say with certainty that this is one of the biggest bullshit problems I've ever done. This is so ridiculously hard it's insane
@YT.Nikolay
@YT.Nikolay 2 жыл бұрын
High caloric video :D the hardest part for me is to figure out how to build the correct graph >_
@subee128
@subee128 8 ай бұрын
Thank you very much
@AhmedGhazey
@AhmedGhazey 2 жыл бұрын
class Solution { public List findAllRecipes(String[] recipes, List ingredients, String[] supplies) { Map graph = new HashMap(); Map inDegree = new HashMap(); Set suppSet = new HashSet(); for (int i = 0; i < supplies.length; i++){ suppSet.add(supplies[i]); } for (int i = 0; i < recipes.length; i++){ graph.put(recipes[i], new ArrayList()); inDegree.put(recipes[i],0); } for (int i = 0; i < recipes.length; i++){ List ingredient = ingredients.get(i); for(String ing : ingredient ){ if (!suppSet.contains(ing) && graph.containsKey(ing)){ String parent = ing; String child = recipes[i]; graph.get(parent).add(child); inDegree.put(child, inDegree.get(child)+1); }else if (!suppSet.contains(ing)){ inDegree.put(recipes[i], inDegree.get(recipes[i])+1); } } } Queue sources = new LinkedList(); for (Map.Entry entry : inDegree.entrySet()){ if (entry.getValue() == 0){ sources.add(entry.getKey()); } } List result = new ArrayList(); while (!sources.isEmpty()){ String vertex = sources.poll(); result.add(vertex); List children = graph.get(vertex); for(String child : children){ inDegree.put(child, inDegree.get(child)-1); if ( inDegree.get(child) == 0) sources.add(child); } } return result; } }
@iamnoob7593
@iamnoob7593 9 күн бұрын
graph map is not filled
@MinhNguyen-lz1pg
@MinhNguyen-lz1pg Жыл бұрын
Didn't know you need a college degree to cook thessdays
@johnj171
@johnj171 2 ай бұрын
nice intimidation liked and subscribed
@bEaStOFtube
@bEaStOFtube 8 ай бұрын
my solution beats 90% (python): class Solution: def findAllRecipes(self, recipes: List[str], ingredients: List[List[str]], supplies: List[str]) -> List[str]: res = [] supplies_set = set(supplies) rec_set = set(recipes) seen = {} def dfs(i): if i in seen: return seen[i] seen[i] = False ing = ingredients[i] can_make = 0 for item in ing: if item in supplies_set: can_make += 1 elif item in seen and seen.get(item): can_make += 1 elif item in rec_set and item not in supplies_set and dfs(recipes.index(item)): can_make += 1 if can_make == len(ing): supplies_set.add(recipes[i]) seen[i] = True return True return False for i, r in enumerate(recipes): if dfs(i): res.append(r) return res
إخفاء الطعام سرًا تحت الطاولة للتناول لاحقًا 😏🍽️
00:28
حرف إبداعية للمنزل في 5 دقائق
Рет қаралды 78 МЛН
Smart Sigma Kid #funny #sigma
00:14
CRAZY GREAPA
Рет қаралды 6 МЛН
Kluster Duo #настольныеигры #boardgames #игры #games #настолки #настольные_игры
00:47
EXCLUSIVE TIME OF FUNCTIONS | LEETCODE 636 | PYTHON SOLUTION
15:42
Cracking FAANG
Рет қаралды 4,9 М.
How I animate 3Blue1Brown | A Manim demo with Ben Sparks
53:41
3Blue1Brown
Рет қаралды 548 М.
Leetcode 46. Permutations : Introduction to backtracking
10:06
ComputerBread
Рет қаралды 99 М.
3 Types of Algorithms Every Programmer Needs to Know
13:12
ForrestKnight
Рет қаралды 484 М.
Alien Dictionary - Topological Sort - Leetcode 269 - Python
22:05
RANDOM PICK INDEX | LEETCODE # 398 | PYTHON RESERVOIR SAMPLING
14:56
Shortest Bridge - Leetcode 934 - Python
14:51
NeetCode
Рет қаралды 38 М.
REMOVE DUPLICATE LETTERS | LEETCODE 316 | PYTHON STACK SOLUTION
18:15
Cracking FAANG
Рет қаралды 2,1 М.
إخفاء الطعام سرًا تحت الطاولة للتناول لاحقًا 😏🍽️
00:28
حرف إبداعية للمنزل في 5 دقائق
Рет қаралды 78 МЛН