Accenture Interview Question
Anonymous User
625

I'm still in college and applied for a part-time job, one of the questions (out of 5) they asked me:

In a company’s hierarchy, some employees manage other employees, who can in turn manage other employees. The input (as a string) format for the hierarchy is (name, sub-hierarchy_1, sub-hierarchy_2, … , sub-hierarchy_n), with every sub-hierarchy having the same format, recursively. Your task is to write code that parses the hierarchy, removes employees that are marked as “Unavailable” along with all the employees they manage and prints the resulting hierarchy.

Input: (“John”, (“Jasmine”, (“Jay”), (“Unavailable”)), (“Unavailable”, (“Jack”, (“Jeremy”))), (“Johanna”))

Output: (“John”, (“Jasmine”, (“Jay”)), (“Johanna”))

Note: The input must be read as a string

I was thinking of a recursive descent parser, but I'm not sure how to make it happen, any tips would be appreciated!

Comments (0)