How do I find the above without removing the largest element and searching again? Is there a more efficient way to do this? It does not matter if the these elements are duplicates.
How do I find the above without removing the largest element and searching again?
Share
You could either initialize
largestandsecondto an appropriate lower bound, or to the first two items in the list (check which one is bigger, and don’t forget to check if the list has at least two items)