Online Assessment
Part 1: Data Center Registration and Health State Management
Need to implement the following two commands:
- REGISTER <region> <latitude> <longitude> <capacity>: registers a data center, with a default health state of healthy.
- SET_HEALTHZ <region> <state>: sets the health state of a given data center (true for healthy, false for unhealthy).
Validation rules:
- Latitude must be in the range [-90, 90]
- Longitude must be in the range [-180, 180]
- Capacity must be greater than 0
- For REGISTER, the region must not already be registered; for SET_HEALTHZ, the region must already be registered
- Latitude, longitude, and capacity are all integers; healthz is a boolean
- Return OK on success, ERROR on failure
Part 2: Computing the Haversine Distance
Implement the command: DISTANCE <lat1> <long1> <lat2> <long2>, which computes the distance between two points.
Rules:
- Implement it using the Haversine formula given in the problem statement
- Inputs are integers, and the output must be rounded to an integer
Part 3: Proximity-Based Routing
Implement the command: ROUTE <latitude> <longitude>, which computes and routes to the nearest healthy region based on the given coordinates.
Rules:
- If a region is unhealthy, it cannot be a routing target and cannot be included in the candidate list
- All registered regions start with a load of 0
- Routing target selection: prefer the nearest healthy region; if distances are tied, pick by alphabetical order
- If there is no available healthy region, output NONE 0
- Output format: <selected region> <distance to that region> <candidate healthy region list (sorted per the rules, space-separated)>
Discussion
Loading comments…