SushiNori has a team of chefs to work its two chef stations. The chefs make requests to management for days they prefer to have off each week. You've been asked to determine whether it's possible to arrange the weekly schedule in such a way that all chefs will get to take their preferred days off while keeping the restaurant staffed.
SushiNori is open seven days a week. Each workday consists of two shifts of 8 hours each. There are restrictions on how many hours employees may work:
- No employee may log more than 40 hours in a week.
- No employee may exceed 5 days of work in a week.
- No employee may work more than 8 hours in a day.
Complete the function
boolean schedulable(HashMap > requests); where requests is a HashMap mapping each chef name to a list of days that chef has requested off for this week:
The string days of the week are guaranteed to be chronologically sorted.
Return true if it's possible to schedule all chefs such that all shifts are covered and all chefs' requests for days off are satisfied and false otherwise.
- Example 1
HashMap > requests = new HashMap<>();
requests.put( "ada", new ArrayList<>(Arrays.asList( new String[] {"mon", "tue", "wed", "fri", "sat", "sun"} )) );
requests.put( "emma", new ArrayList<>(Arrays.asList( new String[] {"tue", "wed", "thu", "sun"} )) );
requests.put( "remy", new ArrayList<>(Arrays.asList( new String[] {"mon", "sat"} )) );
requests.put( "zach", new ArrayList<>(Arrays.asList(new String[] {})) );
ChefScheduler.schedulable(requests);This call to schedulable should return true. Monday has been requested off by two chefs, for example, but Emma and Zach can cover. No chef will be overworked. Here is a possible schedule (all shifts are 8 hours):
Monday : Emma, Zach
Tuesday : Zach, Remy
Wednesday : Zach, Remy
Thursday : Remy, Ada
Friday : Remy, Emma
Saturday : Emma, Zach
Sunday : Zach, Remy
- Example 2
HashMap > requests = new HashMap<>();
requests.put( "emma", new ArrayList<>(Arrays.asList( new String[] {"sun"} )) );
requests.put( "remy", new ArrayList<>(Arrays.asList( new String[] {"sun"} )) );
requests.put( "zach", new ArrayList<>(Arrays.asList(new String[] {})) );
ChefScheduler.schedulable(requests);This call to schedulable should return false because Zach will be unable to cover Sunday alone.
- Example 3
HashMap > requests = new HashMap<>();
requests.put( "ada", new ArrayList<>(Arrays.asList( new String[] {"mon", "tue", "wed", "thu", "fri", "sat"} )) );
requests.put( "emma", new ArrayList<>(Arrays.asList( new String[] {"tue", "wed", "thu", "sun"} )) );
requests.put( "remy", new ArrayList<>(Arrays.asList( new String[] {"mon", "fri", "sun"} )) );
requests.put( "zach", new ArrayList<>(Arrays.asList(new String[] {})) );
ChefScheduler.schedulable(requests);This call to schedulable should return false because Zach would have to work in excess of 5 days in order to cover all needed shifts.