My company has given me a list containing the name
of each employee along with the name of his supervisor (who is also an employee) if
he has one.
The company wants to know whether the list is consistent and, if so, how many
of the employees are supervisors (supervise at least one employee).
"Consistent" means that there is no supervision cycle in which A supervises himself or A supervises B who
supervises C ... who supervises A. It is permissible to have multiple employees who
have no supervisor.
But ... we have Bob trouble. All the employees have distinct names, except that there
may be multiple distinct employees whose names are "BOB". So there may be multiple
ways to put together the supervision hierarchy. We want to construct the
hierarchy so as to minimize the number of supervisors.
Create a class BobTrouble that contains a method minSupers that is given a String[]
name and a String[] bossName giving the names of all the employees and their bosses.
It returns the minimum number of supervisors that can appear in the supervision
hierarchy. If no supervision hierarchy is consistent, it returns -1.
Each element of name refers to a distinct employee, and the supervisor of the
i-th element is given by the i-th element of bossName ("*" indicates
that the employee has no supervisor). Every employee is listed in name.
|