Beta

Restaurant Closing Time

Description:

Introduction

It's the early morning at a world famous, 5 star restuarant. People wait in line ages to get a seat here. Your task is, given a list of groups waiting, and a list of the available tables in the restaurant, what time will the restaurant close?

Input

Group[] queue:

An array of groups waiting at the door.

Group is a preloaded record as below. You can access the object's size(), timeTaken(), hashCode(), equals(), and toString()

public record Group(int size, int timeTaken) {}

Ex: {new Group(2,30), new Group(4,60)} means that there are two groups in line. The first group needs to have 2 people seated, and they will take 30 minutes to eat. The second group has 4 people and will take an hour to eat.

int[] tables:

An array with the capacity of each table in the restuarant.

Ex: {2, 2, 2, 2} means there are 4 tables, each with a capacity of 2

Output

The time the restaurant will close, as a string, in the format "HH:MM" Note that, after 23:59, the time will overflow back to 00:00.

Rules

Restaurant hour

  • The restaurant opens at 06:00 every day
  • Since customer experience is the utmost priority, the restaurant will stay open until every group has left and all tables are clean (even if this spans many days)
  • No new groups will arrive during the day
  • You can consider there to be an endless supply of servers, cooks, and cleaners. There will always be someone available to do the work
  • If there are no customers in line, the restuarant will close immediately

Cleaning tables

  • It takes 5 minutes to clean a table after a group has left
  • Tables must be cleaned after every use
  • Tables do not have to be cleaned if they are unused at the end of the day

Host seating

  • Seating a group is instant
  • Groups are seated in the order they arrive (the order of the array)
  • Groups must sit at a table the same size of the group, or larger
  • Groups will never share a table with another group
  • The host will always try to place a group in the smallest possible table that they fit in
  • If a group can't be seated, and there are no tables at the restaurant that will ever fit that group size, they will leave the line and leave a nasty review (no effect on closing time).
  • If a group can't be seated, but there are tables of a suitable size occupied, they will wait until a suitable sized table is available.
  • If a group can't be seated yet and there is a smaller table available, the host will try to seat the next group that fits in the available table. Queue position priority remains the same.
  • The host isn't very smart, so they will not make any other judgements to speed up the line other than the ones listed above

Example

Input:

queue = {new Group(3,30),new Group(3,15),new Group(1,40),new Group(4,50)} tables = {2,3}

  • Start time: 06:00
  • First group is seated at table 3 and eats for 30 mins
  • Second group has nowhere to sit and must wait
  • Third group is seated at table 2 and eats for 40 mins
  • Fourth group is too large for all tables. They leave the queue
  • 06:30
  • First group is finished eating. Table 3 is cleaned
  • 06:35
  • Second group is seated at table 3 and eats for 15 minutes
  • 06:40
  • Third group finishes eating. Table 2 is cleaned
  • 06:45
  • Table 2 is clean. No one else to seat
  • 06:50
  • Second group's finishes eating. Table 3 is cleaned
  • 06:55
  • Table 3 is clean. No one else to seat
  • Return "06:55" as the closing time

Good luck!

Date Time
Arrays
Games

Stats:

CreatedAug 2, 2024
PublishedAug 6, 2024
Warriors Trained32
Total Skips1
Total Code Submissions66
Total Times Completed9
Java Completions9
Total Stars6
% of votes with a positive feedback rating100% of 3
Total "Very Satisfied" Votes3
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes0
Total Rank Assessments3
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • zkinvig Avatar
Ad