mask mode leaner code for max/min len iteration