Design a Number Container System
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Design a system of numbered containers, where each container index holds at most one number.
- NumberContainers() creates a system with every container empty.
- change(index, number) puts number into container index. If the container already holds a number, that number is replaced.
- find(number) returns the **smallest index** of a container currently holding number, or -1 if no container holds it.
Indices can be very large, so do not allocate an array over the index range.
Examples
Constraints
- `1 <= index, number <= 10^9`
- At most 10^5 calls in total.
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.