Company: Tower Research

Difficulty: medium

Problem Statement

Minimum Height of a Tree After Reattaching Subtrees Given a rooted tree with root 1, you may at most k times remove a parent-to-child edge `(u,v)` and connect `v` directly to root 1. The subtree rooted at v moves with it. Print the minimum possible tree height, where height is the maximum number of nodes on a root-to-leaf path. Input Format The first line contains n and k. The second line contains n-1 parent values `tree_from`. The third line contains n-1 child values `tree_to`; matching positions form directed edges. Output Format Print the minimum height. Constraints - 2 <= n <= 200000 - 0 <= k <= n-1

More Tower Research OA questionsInterview experiences