Practice Design a Number Container System
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Design a Number Container System
Problem Statement
NumberContainers starts empty. change(index,number) stores a number at an index, replacing any previous one. find(number) returns its smallest current index or -1 if absent. Practice approach: Track index-to-number assignments and a min-heap of candidate indices for each number. On find, discard heap entries whose current assignment differs. Alternatively use ordered index sets with eager removals. Replacement must stop the old number from claiming that index. Test changing the smallest matching index and assigning the same value again.
Source: Design a Number Container System on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
["NumberContainers","change","change","find","change","find","find"] [[],[4,7],[2,7],[7],[2,9],[7],[9]]
[null,null,null,2,null,4,2]
Replacing index 2 moves the smallest index for number 7 to 4.
Constraints
Related LeetCode Problems
Practice more problems similar to Design a Number Container System.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.