Problem Statement: In the large corporation Techify Inc., there is a hierarchical structure of employees. The company has N employees, each identified by a unique ID from 1 to N. At the top of this structure is the CEO, who serves as the root of the company's hierarchy.
Employees report to their immediate supervisors except for the CEO, who has no supervisor. The company is undergoing a restructuring process because some employees have become non-compliant.
Compliant: An employee is compliant if they respect the company's policies and directives given by their supervisor.
Non-Compliant: Some employees have grown dissatisfied and no longer respect their supervisor's authority.
To streamline the company, management has decided to identify and remove non-compliant employees, but with specific criteria:
Select a non-compliant employee (one who does not respect their supervisor) who also has no compliant subordinates (i.e., all of their direct and indirect reports are either also non-compliant or they are a leaf node with no reports).
If there are multiple such employees eligible for removal, break the tie by selecting the employee with the smallest unique ID.
When an employee is removed, their immediate subordinates are directly reassigned to the removed employee's supervisor.
Task: Write a program to determine the order in which these non-compliant employees will be removed from the company.
Return Format: Return an array/list of integers representing the IDs of the employees in the exact order they are removed. If no employees meet the criteria for removal, return an empty array or -1 (depending on the specific compiler instructions).