Return the minimum set of nodes to delete so a rooted tree has height at most k.
Unlock detailed company stats for this questionUpgrade
Given a graph of height >= k rooted at node 0, return the minimum set of nodes to delete (not the count) such that the resulting tree has height at most k. Deleting a node removes it from consideration in the height count, but everything in its subtree is still included.
Examples when also maximizing the score of the deleted nodes (minimizing the sum of their heights, prioritizing nodes lower in the tree):
- n=5, edges=[[0,1],[1,2],[2,3],[3,4]], k=3 gives min size 2, min score 3 (nodes 3 and 4)
- n=7, edges=[[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], k=2 gives min size 1, min score 3 (node 0)
- n=7, edges=[[0,1],[0,2],[0,3],[3,4],[4,5],[5,6]], k=2 gives min size 3, min score 6 (nodes 4, 5, 6)
- n=6, edges=[[0,1],[1,2],[2,3],[0,4],[4,5]], k=3 gives min size 1, min score 2 (node 3)
Expect follow-ups like
- Among minimum-size deletion sets, also maximize the score of the deleted nodes, essentially minimizing the sum of their heights and prioritizing nodes lower in the tree.
Community answers
No answers contributed by the community yet.
Related questions
Find the minimum moves to visit all critical nodes in a tree and return to the root.Find the minimum cost to remove all leaf nodes of an edge-weighted binary tree.Find the minimum cost to disconnect all leaves from the root of a weighted binary tree.Related courses

Course

Course
Course
