Started with a hash map keyed by id, which felt obvious, and the interviewer seemed fine with that.
Start by clarifying requirements and constraints, then propose a primary data structure (e.g., a hash map keyed by id) for O(1) CRUD operations. Discuss secondary indexes for name and email, and explicitly define error handling for missing ids and duplicate emails, including whether to throw exceptions or return optionals.
Pro tip: Mention that email uniqueness should be enforced with a secondary index, and consider case-insensitivity and normalization (e.g., lowercasing) to avoid subtle bugs. Also, discuss thread-safety if the class is to be used concurrently.
Ask about expected operations, concurrency needs, and whether name/email lookups must be exact or partial. Confirm that id is immutable and unique, and that email must be unique.
Use a hash map (e.g., HashMap<Integer, Employee>) for O(1) get, update, and delete by id. Ensure Employee objects are immutable or that id cannot be changed.
Maintain additional maps for name and email (e.g., HashMap<String, Set<Employee>> for name, HashMap<String, Employee> for email). Update these indexes atomically with primary storage on insert, update, and delete.
For missing id, return null/optional or throw a custom exception (e.g., EmployeeNotFoundException). For duplicate email, throw a DuplicateEmailException or return a conflict status. Be consistent and document behavior.
Mention memory overhead of indexes, complexity of maintaining consistency, and potential need for transactions or locking. Suggest alternatives like database unique constraints if persistence is involved.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.