You are building a web site for your clients to access, and want to create a welcome screen that serves as a starting point where they can view various pieces of data.
All of your data is stored hierarchically in folders, much like a file system. You are given a String[] folders, where each element includes the id of the parent folder, a space, and a comma-delimited list of users who have permission to view that folder. The root level folder, 0, is its own parent, and all folders are descendants of the root node. Additionally, you are given a String[], users, which contains a list of the users who will be accessing the web site.
For each user, you are to determine which folder should serve as their "home folder". A user's home folder is defined as the deepest folder which contains all of the folders the user can access.
Suppose the data is very simple, such that folders looks like this:
folders = { "0 Administrator",
"0 Joe,Phil",
"0 Joe" }
and your users are Administrator, Joe, and Phil. Clearly, the Administrator's home folder is 0, since he can access the root node. Similarly, Phil's home folder is 1, since he can only access folder 1. But Joe can access folders 1 and 2, so his home folder must be folder 0, which contains folders 1 and 2.
The return value should be a int[], indicating the home folder for each corresponding element of users. Users who have access to no folders are assigned a home folder of -1.
|