Company: uber_6oct
Difficulty: medium
Problem Description In Uber's system, driver assignments are organized in a hierarchical tree. The root node (Driver 1) represents the central dispatcher, and each driver node may supervise other drivers. The height of this tree is defined as the maximum number of links (edges) between the dispatcher (Driver 1) and any other driver. To optimize communication, Uber allows at most max_reassignments operations to restructure the hierarchy. In a single reassignment operation, you can: Select a driver u who currently reports to a manager v (where v ≠ 1 ). Remove the reporting link between u and v . Reassign u (along with their entire subtree/team) to report directly to the dispatcher (Driver 1). Write a SQL query to determine the minimum possible height of the driver hierarchy after performing at most max_reassignments operations. Schema Table: Hierarchy manager_id (INT): The driver ID of the manager (the parent node of the reporting link). emp_id (INT): The driver ID of the reporting dr