A faster way to find min and max in array