The validation rules look obvious on paper but I initially forgot that capacity zero should also fail, not just negatives.
Clarify the command interface and validation rules, then design a data structure that supports O(1) registration and health toggling. Implement the commands with strict input validation, ensuring unique names and proper error handling, and test edge cases like boundary coordinates and duplicate names.
Pro tip: Mention that you would use a hash map for O(1) lookups and discuss how to handle floating-point precision for lat/lon validation. Also, consider thread-safety if the system is concurrent, as Stripe values robust, production-ready code.
Ask about input format, expected output, and any constraints like maximum number of datacenters or concurrency. Identify edge cases such as boundary values for lat/lon, zero capacity, and duplicate names.
Choose a hash map (e.g., dictionary) to store datacenters by name for O(1) access. Each datacenter record should include name, latitude, longitude, capacity, and a healthy flag.
For REGISTER, validate that latitude is between -90 and 90, longitude between -180 and 180, capacity is positive, and name is unique. For SET_HEALTHY, validate that the datacenter exists and the healthy flag is a boolean.
Parse each command, execute the corresponding operation, and print OK if successful or ERROR if validation fails. Ensure that failed operations do not modify the state.
Walk through test cases including valid and invalid inputs. Discuss time/space complexity (O(1) per operation) and potential improvements like thread-safety or persistence.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.