DELETE NODES AND RETURN FOREST | LEETCODE # 1110 | PYTHON DFS SOLUTION

  Рет қаралды 3,870

Cracking FAANG

Cracking FAANG

Күн бұрын

Пікірлер: 14
@StellasAdi18
@StellasAdi18 2 жыл бұрын
Not the easiest problem… feels easy the way you explained. Thanks for explaining it.
@rsKayiira
@rsKayiira 2 жыл бұрын
Great solution this is not easy for me but well explained. Could you please add LC 825 Friends of Appropriate Ages
@Lord-vq5rh
@Lord-vq5rh Жыл бұрын
Nice Explanation
@usamabaig5856
@usamabaig5856 5 ай бұрын
How is T: O(n) + O(D), if for every node we are checking if its in to_delete then shouldn't it be O(n) * O(D), what am I missing?
@cpuneet98
@cpuneet98 5 ай бұрын
very helpful
@MrZiyak99
@MrZiyak99 2 жыл бұрын
hey so if node.left.val is in to delete why do we set it as a root?
@yousifshamoun5376
@yousifshamoun5376 2 жыл бұрын
If the node.val is in to_delete then is_root will never be checked so we could have set it to anything
@floriandubost5484
@floriandubost5484 2 жыл бұрын
Yes, as Yousif said, this is kind of redundant. The code below does not have this and also runs: class Solution: def delNodes(self, root: Optional[TreeNode], to_delete: List[int]) -> List[TreeNode]: out = [] to_delete = set(to_delete) def dfs(node, is_root): if not node: return if node.val in to_delete: dfs(node.left, True) dfs(node.right, True) else: dfs(node.left,False) dfs(node.right,False) if node.left and node.left.val in to_delete: node.left = None if node.right and node.right.val in to_delete: node.right = None if is_root: out.append(node) dfs(root, True) return out
@ryantomlinson9426
@ryantomlinson9426 Жыл бұрын
+1 to this, it's a bit confusing setting that to root, but no matter what you set it to it still passes. I'd set it to False just for clarity.
@somethingNewAndGood
@somethingNewAndGood Жыл бұрын
@@floriandubost5484 This is an awesome solution! A bit cleaner as well.
@averychen4633
@averychen4633 10 ай бұрын
@@floriandubost5484 Thank you. I was so confused by the code in the video. Your response is clearer!
@seungminchoi8381
@seungminchoi8381 Жыл бұрын
Do you know how to do this without modifying the given tree?
@lavanya_m01
@lavanya_m01 7 ай бұрын
I guess the problem expects us to modify the tree coz we've to return the roots after deleting certain nodes.
INSERT INTO CIRCULAR LINKED LIST | LEETCODE # 708 | PYTHON SOLUTION
15:25
How to code like a FAANG Software Engineer - Follow this one pattern!
13:28
When Cucumbers Meet PVC Pipe The Results Are Wild! 🤭
00:44
Crafty Buddy
Рет қаралды 61 МЛН
LRU CACHE | LEETCODE 148 | PYTHON LINKED LIST SOLUTION
15:30
Cracking FAANG
Рет қаралды 960
DATA STRUCTURES EXPLAINED!!
19:18
James Peralta
Рет қаралды 160
Meta Technical Interviews in 2024: What You Need to Know Now!
14:13