📜 ⬆️ ⬇️

A challenge from a foreign company or how I failed an interview

Having decided to try my hand at a foreign market, I started sending resumes to various offices. Not even for the purpose of finding a job, but simply for expanding the horizons. The choice fell on the job "Java Developer". I have no industrial experience with the language, only personal experience, certificates from the Oracle Certification Center, books, etc. Honestly, at the last job in one and a half years I didn’t write anything except for the “odds” and “ifs” (but this is a completely different story), so I decided why not.

Skipping the history of the search and conversations with employers, move on to the point. One company K from city G wrote that they were interested in having an interview with me after I solved the problem.

After I decided and sent them the decision, K replied that after the review code they decided not to review my application more. It was a blow to my self-esteem. Of course, I understand that the language is new, and in general anything happens, but I hoped for at least a review of my decision. Plus, the task is really simple ... I hope you will be interested in the task.

Below is the original text of the problem.

RESTAURANT EXERCISE


image

RESTAURANT EXERCISE (please use JAVA 7 syntax)

Your table has a set of tables of different sizes: each table can accommodate 2, 3, 4, 5 or 6 persons. Clients arrive alone or in groups, up to 6 persons. It is therefore a group that can accommodate them all. There is a table where you can wait in the queue.

Once seated, you can’t make it.

In the case of a group of children, it’s not a problem. For example, if there is a table for two, there is a table for two people.

There are no chairs for people to use. , even if the table is bigger than the size of the group.

It’s not worth it.

Please complete the RestManager class with the data methods. You will be able to modify them.

public class Table { public final int size; // number of chairs } public class ClientsGroup { public final int size; // number of clients } public class RestManager { public RestManager (List<Table> tables) { // TODO } // new client(s) show up public void onArrive (ClientsGroup group) { // TODO } // client(s) leave, either served or simply abandoning the queue public void onLeave (ClientsGroup group) { // TODO } // return table where a given client group is seated, // or null if it is still queuing or has already left public Table lookup (ClientsGroup group) { // TODO } } 

Task analysis


After analyzing the task, it seemed to me and it seems now, well, there is nothing absolutely complicated. However, I immediately want to draw attention to two points that confused me a little.

  1. "If you’re looking for a group of children, it’s not worth it."
  2. RestManager class structure

Regarding the first paragraph, the fact is that our distribution system works according to the above rules, so the situation described in paragraph 1 cannot be avoided. The only thing that I wrote in the reply letter, you can add a delay before issuing a free table. Let's say a group of 3 people comes to a restaurant. At the moment there is a single table on the 6th. By condition, we are obliged to provide them with a table (you must always have a seat at your empty table ... even if there is a table). But if this is not done immediately, but after 5 minutes. During this time there is a chance, albeit a small one, that a place or table with less dimension will be freed. But it looks frivolous of course.
On the second point, at least IMHO, the public Table lookup method is not in its class. We can get the table as a getter from a client who, according to ideas, should keep a link to the table.

In general, I highlighted two main points:

  1. It is necessary to sort the tables in the correct order. The logic of finding the right table is simply transferred to sorting. The first table that can accommodate a group of customers and will be necessary.
  2. Only two events necessitate a table search for a client or a client for a table. This is the arrival of a new customer and after the group left the table accordingly.

Actually, the whole task comes down to the two points above. By the way, the queue collection is useless. The queue is a queue, but by condition any of the queues can be served, depending on the available seats and the size of the group, and as a result, we will not use the methods related to the queue.

I leave the link to git with the solution: RestaurantTask

Source: https://habr.com/ru/post/436282/