This problem consists of two parts which are described as follows:
There are some customers of a hotel group touring on an island far away from here. The island was hit by an earthquake. Therefore, the customers were asked to remain wherever they are so that help could be sent to them soon. Thanks to the GPS on their phone, we know how many customers were present on the island and also their exact location. In order to best utilize the rescue resources, the customers are asked to move from their places to meet at least one other person on that island.
The customers are mapped to a single line around the center of the island which can be imagined as
an x-axis. Develop a RESTful API /customers-and-hotel/minimum-distance which
takes in a list of integers (representing X axis location of the stranded customers) and gives out a
number in String format which is the minimum distance the customers have to move in order to meet
any other customer stranded on the island.
List of Integers
A whole number indicating the minimum distance that any customer needs to move.
[4, 7, 5, 1, 12, 13, 9, 2, 6, 3, 21]
{
"answer":1
}
The earthquake caused a lot more damage than anticipated, hence the rescue resources like food and medical supplies will arrive later than expected. Also, there are only a few amount of relief camps that the hotel can build to help the stranded customers. Waiting for the help, the customers are tired and now each one of them can only walk a certain unit of distance.
Develop a RESTful API /customers-and-hotel/minimum-camps that takes in a list of the position of the customer and
the distance the customer can walk in left or right direction and returns a number in String format
which indicates the minimum number of camps required to be built by the hotel.
A list of the customer information objects where "pos" determines the position of the customer on a straight line (X-axis) and the "distance" indicates the distance from its position on X-axis that the customer can walk either to his left or to his right.
A whole number indicating the minimum number of camps need to be built by the hotel.
[
{
"pos":4,
"distance":3
},
{
"pos":7,
"distance":1
},
{
"pos":5,
"distance":1
},
{
"pos":1,
"distance":1
}
]
{
"answer":2
}
Successfully solving the first part will grant you 30 percent of the total score, and the second part will grant the remaining 70 percent.
/customers-and-hotel/minimum-distance and
/customers-and-hotel/minimum-camps