Company: uber_6oct
Difficulty: medium
Problem Description A ride-hailing platform organizes its driver assignments as a hierarchical tree. The root node (Driver 1) represents the central dispatcher, and each driver node may supervise other drivers below it. Define the height of this tree as the largest number of links (edges) found on any path from the dispatcher (Driver 1) out to another driver. The platform allows up to max_reassignments restructuring operations to shrink this hierarchy. In one such operation, you may: 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 that finds the smallest achievable height of the driver hierarchy after performing at most max_reassignments such 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 rep