← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
You are given a rooted tree with n nodes (0-indexed) and an integer k. The tree is represented by an array parent of length n where parent[i] is the parent of node i, and parent[0] = -1 indicating that node 0 is the root. The height of the tree is the maximum number of edges on any path from the root to a leaf. Your task is to delete the minimum number of nodes so that the resulting tree has height at most k. When a node is deleted, its entire subtree is removed. Return the minimum number of deletions required.