Part 1 {/customers-and-hotel/minimum-distance}

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.

What is the minimum distance that any person has to move in order to meet any other person on the 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.

Inputs:

List of Integers

Constraints:
  • All input numbers are non-negative integers
  • N <= 104 (N=number of stranded customers)
  • 0 <= xi <= 1015 (xi=X axis location of a stranded customer)
Output Format

A whole number indicating the minimum distance that any customer needs to move.

Sample Input
                    
    [4, 7, 5, 1, 12, 13, 9, 2, 6, 3, 21]
                
Sample Output
                    
    {
       "answer":1
    }
                

Part 2 {/customers-and-hotel/minimum-camps}

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.

What will be optimum number of relief camps that can be placed on the island so that each customer can walk to the camp given the walking range of each customer?

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.

Inputs:

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.

Constraints:
  • All input numbers are non-negative integers
  • N <= 103 (N=number of stranded customers)
  • 0 <= pos <= 1015
  • 0 <= distance <= 109
Output Format

A whole number indicating the minimum number of camps need to be built by the hotel.

Sample Input
                    
    [
        {
           "pos":4,
           "distance":3
        },
        {
           "pos":7,
           "distance":1
        },
        {
           "pos":5,
           "distance":1
        },
        {
           "pos":1,
           "distance":1
        }
    ]
                
Sample Output
                    
    {
       "answer":2
    }
                

Evaluation

Successfully solving the first part will grant you 30 percent of the total score, and the second part will grant the remaining 70 percent.

Requirements

  • Expose two POST method with endpoint /customers-and-hotel/minimum-distance and /customers-and-hotel/minimum-camps
  • Return a whole number as response in both of them