In this article, I will explain how to use the max heap to track the furthest enemy on the map.The answer to this question is the building block towards enabling towers to track enemies more effectively.The current implementation uses an array enemySpatialGrid that tracks enemies in each cell on the map.Sorting items generally takes O(N logN), this is slower than max heap.An update is done similarly to adding a new enemy. Except we need to know the enemy’s position in the heap.To achieve deletion, we need to take three steps.Since the heap is already sorted, we just need to grab the first element in the heap.Max heap successfully solved the problem. Now we know the furthest enemy on the map.Additionally, the max heap is more performant than the existing implementation.Lastly, its implementation paves the way to integrating it with towers.