solve max<min in a better way