Traverse from right to left for odd rows
for ( int j = c - 1 ; j >= 0 ; j -- ) { if ( arr . get ( idx - 1 ) == 0 ) idx ++ ; dp [ i ] [ j ] = idx ; arr . set ( idx - 1 , arr . get ( idx - 1 ) - 1 ) ; } } }