To design a API,
get()
, it will return the random number, also the number should not duplicate, means it always be unique.put(randomvalue)
, it will put back the generated random number fromget()
, if put back,get()
function can reuse this number as output.
It has to be efficient, no too much resource is highly used.
Is there any way to implement this algorithm? It is not recommended to use hashmap, because if this API generate for billions of requests, saving the generated the random number still use too much space.
I could no work out this algorithm, please help give a clue, thanks in advance!