Which is better choice out of two different implementation
Hi Refer code below : Both the codes will have global variables as member variable of class say for example management... This is not concern and just wrote them as global to showcase the main question. Which is better ? Implementation 1 or Implementation 2? I feel 2 is better as it does not ask to iterate over all the persons and just maintains the required values in terms of person ids. If another field is there like isSick , we can have another list. This implementation has overhead of storing extra details... Obviously extra memory usage will give us better time complexity and hence #2 is better than #1. But I don't want to simply ignore #1. Is #2 easy to manage ? I mean there can be number of methods like some random events which all will update person unordered map as well as additional data member like lstVeg In terms of code design and maintainability and code readability, is #2 ok to go ahead with ? If not, #1 is the only way with a bad time complexity or is there any other approach ? htt