Improvement on O(N*N) solution
I am having a list of object which gets modified. Modification is either removal of object from list or addition of object to list. Logic to check removal is some what not good that is what I feel as it is O(N*N). It actually checks one with all other. Can I improve this logic? Refer code below for more clarity: https://code.sololearn.com/cyyYiGLuJ7BO I just need to improve checkCollosion() function. Any thoughts? P.s. : I forgot to add my thoughts and confusion on same... I thought to add map instead of list ...key will be position and value will be object... But will map work on dynamic additional object creation when iterator is iterating over in update function ? That's why I thought to raise the query... If used map, just check with few only as it is sorted data... Plus map insertion and deletion is costly compared to corresponding operation on list