update the O(n) solution for max array