Binary Tree - 57: Remove nodes which don’t lie in any path from root to leaf with sum greater than k

preview_player
Показать описание

Solution:
- We'll traverse Binary Tree in Post Order manner starting with s = 0 & we'll add current node value when we're traversing any node
- Whenever we find Leaf node, we'll check if total added value is less than given sum. If it's less, we'll return null

- Time Complexity: O(n)
- Space Complexity: O(1)

Do Watch video for more info

This Problem is synonym of following problems:
binary tree Remove all nodes which don’t lie in any path from root to leaf with sum greater than k,
coding simplified,

CHECK OUT CODING SIMPLIFIED

★☆★ VIEW THE BLOG POST: ★☆★

I started my YouTube channel, Coding Simplified, during Dec of 2015.
Since then, I've published over 200+ videos.

★☆★ SUBSCRIBE TO ME ON YOUTUBE: ★☆★

★☆★ Send us mail at: ★☆★
Рекомендации по теме
Комментарии
Автор

take the tree [1, 2, -3, -5, null, 4, null] and key=-1 for example . according to this code the answer is [1, 2, -3, null, null, 4, null] but it should be [1, null, -3, null, null, 4, null] as 2, -5 doesn't exist in any path greater than -1 .

ashgoku