Although the solution to this problem seems difficult at first it is very trivial. We have two different problems we could be asked to solve: 1. Find the min speed. 2. Find the max speed. The approach to each of them is very similar. If we are asked to find the min speed we should attempt to eliminate as many large numbers as possible. If we asked to find the max speed then we should maximize the large numbers. To solve problem 1 we need to match the largest speeds from town a with the largest speeds from town b. To solve problem 2 we need to match the largest speeds from town a with the smallest speeds from town b. This is precisely what my solution below does.