finish reverse max match segmentation algorithm