Squarepoint Capital Interview Question

implement a method to minimize the distance