Find maximum and minimum elements in an array