How would you find the second maximum element of an array?
Implement the solution for an array of integers and return the second largest distinct value. Assume the array contains at least two distinct elements. The function should run in linear time and use constant extra space.
def second_maximum(nums):