Skip to content

Latest commit

 

History

History

221-organizational-hierarchy

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Organizational Hierarchy

Challenge Description:

Everyone who has ever worked in a large organization understands the organizational hierarchy: you, your boss, boss of your boss, and so on.
Because of changes in all directions of the organization, everything was mixed up. From the existing documentation, you can understand only who is a manager and who is a subordinate. We need your help to recreate the whole organizational hierarchy using information from all existing documents.

Input sample:

The first argument is a path to a file. Each line includes a test case with documents separated by a pipeline '|'. There are two letters in each document: 1st one – the manager, 2nd one – the subordinate.

For example:

ab | ae | bc
ab | bc | cd | ae | cx | xz

Output sample:

You should print the hierarchical tree in the following format: if a manager a has two subordinates e and b, then the tree would be a [b, e]. You should sort all workers alphabetically.

For example:

a [b [c], e]
a [b [c [d, x [z]]], e]

Constraints:

  1. Hierarchical tree can be of no more than 4 levels.
  2. Sort all subordinates of one manager in an alphabetical order.
  3. The number of test cases is 15.