Request Routing System
Complete the function below. The function receives the full standard input as a single string and returns the exact standard output lines for a request-routing command processor.
Problem
You are building a request routing system for datacenters. The system supports commands that register datacenters, update their health, compute geographic distance, and route user requests to the nearest available healthy datacenter.
Each datacenter has a unique name, latitude, longitude, capacity, health status, and current load. A newly registered datacenter is healthy and has load 0.
Supported commands:
REGISTER name latitude longitude capacity: add a datacenter. ReturnOKif the name is new, latitude is in[-90, 90], longitude is in[-180, 180], and capacity is greater than0; otherwise returnERROR.SET_HEALTHY name value: set health totrueorfalse. ReturnOKfor an existing datacenter and valid boolean value; otherwise returnERROR.DISTANCE lat1 lon1 lat2 lon2: compute the great-circle distance in kilometers using Earth radius6371and the Haversine formula. Return the nearest integer distance. ReturnERRORfor invalid coordinates.ROUTE latitude longitude: among healthy datacenters, sort by distance to the user ascending, breaking ties by datacenter name. Choose the first datacenter whose current load is less than capacity, increment its load by1, and outputname distance candidates. If no healthy datacenter has capacity left, outputNone candidates.candidatesis the comma-separated ordered list of healthy datacenter names considered by the router.
Process commands in order and return one output line per command.
Complete solveRequestRoutingSystem. It has one parameter, String input, containing newline-separated commands. Return the stdout payload as an array of lines, without trailing newline characters.
1Example 1
The duplicate datacenter name, invalid latitude, invalid capacity, and unknown datacenter update are rejected.
2Example 2
The first distance is rounded to the nearest kilometer; the last command has an invalid latitude.
3Example 3
The unhealthy node-C is not considered. The two healthy nodes are selected once each, then both are at capacity.
Constraints
Limits and guarantees your solution can rely on.
Coordinate validation follows the exact bounds stated in the prompt.
Capacity must be a positive integer.
Distances use Earth radius 6371 km and are rounded to the nearest integer.