Programming Optimization #1: Maximum Element in Array after Removal of Random Element


Suppose you have an Array A = [10,3,4,5,8,9], what is the fastest way to compute the maximum element in one pass after a random element is removed.

Thinking Process

If you are a coder, finding the maximum element is trivial and can be done in one pass by scanning elements one by one and compare the current element to the last largest element encountered. If the current is larger, it is the maximum element for now.