Maximum Binary Tree (LeetCode 654) | Full Solution with a natural way to approach | Recursion

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

Nikhil Lohia

Nikhil Lohia

Күн бұрын

Пікірлер: 11
@lonen3rd
@lonen3rd Жыл бұрын
This is how I did it, in Python. I'm not sure what the overall time complexity is considering there are two O(n) operations for every DFS call where nums is not empty. class Solution: def constructMaximumBinaryTree(self, nums: List[int]) -> Optional[TreeNode]: if not nums: return max_num = max(nums) max_index = nums.index(max_num) root = TreeNode(max_num) root.left = self.constructMaximumBinaryTree(nums[:max_index]) root.right = self.constructMaximumBinaryTree(nums[max_index+1:]) return root
@abdulmutaalazhar8235
@abdulmutaalazhar8235 8 ай бұрын
Hi, really nice explanation. Thank you btw, which drawing pad and drawing software are you using ?
@nikoo28
@nikoo28 8 ай бұрын
that is GoodNotes 6
@tanishkaagarwal6750
@tanishkaagarwal6750 7 ай бұрын
Wonderful explanation
@AniketWaghmare-qi7wm
@AniketWaghmare-qi7wm Ай бұрын
Hey Nikhil Please Make Video On leetcode Question Number 1448. count Good Nodes in Binary Tree using java
@subee128
@subee128 9 ай бұрын
Thanks
@ritikanand3425
@ritikanand3425 Жыл бұрын
Great Explanation
@nikoo28
@nikoo28 Жыл бұрын
Glad you liked it
@rjarora
@rjarora 5 ай бұрын
Bhai brute force bata dia ye to
@nikoo28
@nikoo28 5 ай бұрын
What do you mean?
@athirap2529
@athirap2529 4 ай бұрын
@@nikoo28 I think he meant it's a brute force solution
5 Simple Steps for Solving Any Recursive Problem
21:03
Reducible
Рет қаралды 1,2 МЛН
Всё пошло не по плану 😮
00:36
Miracle
Рет қаралды 3,4 МЛН
😜 #aminkavitaminka #aminokka #аминкавитаминка
00:14
Аминка Витаминка
Рет қаралды 1,8 МЛН
Ouch.. 🤕⚽️
00:25
Celine Dept
Рет қаралды 21 МЛН
Add One Row to Tree | Live Coding with Explanation | Leetcode - 623
11:33
Algorithms Made Easy
Рет қаралды 3,6 М.
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 484 М.
Cousins in a binary tree | Leetcode #993
12:12
Techdose
Рет қаралды 35 М.
My Brain after 569 Leetcode Problems
7:50
NeetCode
Рет қаралды 2,6 МЛН
Всё пошло не по плану 😮
00:36
Miracle
Рет қаралды 3,4 МЛН