Skip to content

2349. Design a Number Container System #1287

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to design a number container system that allows efficient insertion or replacement of numbers at specific indices and retrieval of the smallest index for a given number. The solution must handle these operations efficiently even with a large number of indices and numbers.

Approach

The approach involves using two main data structures:

  1. Hash Map (Associative Array) for Index to Number Mapping: This helps in quickly determining the current number at any given index.
  2. Min-Heap for Number to Indices Mapping: This allows efficient retrieval of the smallest index for a given number. Each number maps to a min-heap that stores all indices where the number is currently located, ensuring that…

Replies: 1 comment 2 replies

Comment options

mah-shamim
Feb 8, 2025
Maintainer Author

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Feb 8, 2025
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants