Minimize distance between sorted arrays