Store all datacentres and their details. Calculate the routing distance
Part 1:
Input:-
REGISTER <region> <latitude> <longitude> <capacity>
SET_HEALTHZ <region> <state>
Sample Input:-
REGISTER us-east-1 38 120 100
REGISTER us-west-2 50 112 30
SET_HEALTHZ us-west-2 false
REGISTER eu-east-1 -10 15 0Output:-
OK (if register is successful)
ERROR (if it fails the rules)Rules:
Part 2:
Calculate the Haversine distance between two sets of coordinates. (Haversine algorithm is given for implementation)
Input:-
DISTANCE <lat1> <long1> <lat2> <long2>
Sample input:-
DISTANCE 0 0 100 100
Output:-
10200
Constraints:-
Input will be integer and output needs to be rounded to integer
Part 3:-
Calculate proximity routing for the given coordinates to a region registered and return the only healthy region and which can handle the load and possible candidates for the routing. Also add the distance of the region from the request. (Based on haversine in part 2)
Input:-
ROUTE <latitude> <longitude>
Sample Input:-
REGISTER us-east-1 0 0 1
REGISTER ap-south-1 0 0 1
ROUTE 0 0
SET_HEALTHZ ap-south-1 false
ROUTE 0 0Output:-
OK
OK
us-east-1 0 us-east-1 ap-south-1
NONE 0 us-east-1Rules:
Time limt is 1Hr and need to process input and output from scratch. Platform is hackerrank.