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

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

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 8 күн бұрын
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 >_
@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 8 күн бұрын
graph map is not filled
@subee128
@subee128 8 ай бұрын
Thank you very much
@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
EXCLUSIVE TIME OF FUNCTIONS | LEETCODE 636 | PYTHON SOLUTION
15:42
Cracking FAANG
Рет қаралды 4,9 М.
didn't manage to catch the ball #tiktok
00:19
Анастасия Тарасова
Рет қаралды 31 МЛН
Un coup venu de l’espace 😂😂😂
00:19
Nicocapone
Рет қаралды 10 МЛН
Can I Run Youtube Entirely From My Terminal? (No Browser)
15:31
Dear Game Developers, Stop Messing This Up!
22:19
Jonas Tyroller
Рет қаралды 719 М.
RANGE MODULE | LEETCODE 715 | PYTHON SOLUTION
29:39
Cracking FAANG
Рет қаралды 7 М.
Use Arc Instead of Vec
15:21
Logan Smith
Рет қаралды 148 М.
Dynamic Programming isn't too hard. You just don't know what it is.
22:31
DecodingIntuition
Рет қаралды 174 М.
Alien Dictionary - Topological Sort - Leetcode 269 - Python
22:05
REMOVE DUPLICATE LETTERS | LEETCODE 316 | PYTHON STACK SOLUTION
18:15
Cracking FAANG
Рет қаралды 2,1 М.
Shortest Bridge - Leetcode 934 - Python
14:51
NeetCode
Рет қаралды 38 М.
didn't manage to catch the ball #tiktok
00:19
Анастасия Тарасова
Рет қаралды 31 МЛН