Post-Order Traversal and Sorted Lists
Interesting problem combining post-order traversal and sorted lists: 1/ Perform a post-order traversal 2/ On each step, return a sorted list with the smallest K elements in the subtree 3/ Insertion operation and merge of sorted lists done in a custom way for speed Time complexity around O(number of nodes * k). Code is down below, cheers, ACC. Count Nodes That Are Great Enough - LeetCode 2792. Count Nodes That Are Great Enough Medium 7 0 Add to List Share You are given a root to a binary tree and an integer k . A node of this tree is called great enough if the followings hold: Its subtree has at least k nodes. Its value is greater than the value of at least k nodes in its subtree. Return the number of nodes in this tree that are great enough. The node u is in the subtree of the node v , if u == v or v is an ancestor of u . Example 1: Input: root = [7,6,5,4,3,2,1], k = 2 Output: 3 Explanation: Number the nodes from 1 to 7. The values in the subtree of node