HackerEarth The maximum distance problem solution