Master Data Structures & Algorithms For FREE at AlgoMap.io!
@siddhantkumar94927 ай бұрын
Thanks for the great explanation! Just to add on, this question can also be done by using any of the 3 traversal techniques, preorder, postorder or inorder and keeping a track of the max at each node. def dfs(root, maxval): if not root: return 0 left = dfs(root.left, max(maxval, root.val)) right = dfs(root.right, max(maxval, root.val)) res = left+right if root.val >= maxval: res+=1 return res return dfs(root, root.val)
@GregHogg7 ай бұрын
Yes that's a great point, totally true. Thanks so much for the kind words :)
@JSH19942 ай бұрын
please keep solving leetcode questions.. your explanations are great
@philipbrujic47284 ай бұрын
Good video
@gingerjiang6663 ай бұрын
What is the reason you solve it iteratively instead recursively? Can you explain it?
@ShahriyarRzayev2 ай бұрын
For me, the iterative approach is easier to understand than the recursive one, and most of the other videos explain using the recursive approach. Maybe this was the reason to record the video to show an alternative to the recursive option.