This problem is troubling me from so long time now.
There are N scientists, K black holes, and any scientist can query about radius, size and temperature of any blackhole.
You have to answer three kinds of query basically:
Given Scientist queried for which black holes,Given scientist queried for which attributes.
Given black hole, who all scientist had queried on it, which attributes of it had been queried upon.
Given attribute which scientist has queried upon it and which black hole has it been queried upon.
All should be in O(1) time complexity.
Which data structure will you use for this?
My Trial: I can think of 3 hashmaps for each option 1,2,3. But, it won't do it in O(1) time. I have thought a lot on this. Please share some algorithm or pseudo code. I don't need any code for this. I just want to see what is the algorithm hidden behind this.
Aucun commentaire:
Enregistrer un commentaire