Problem Link:- CodeChef: Practical coding for everyone


Difficulty - EASY - MEDIUM

Prerequisites - Logic of shortest path, multidimensional array. Good knowledge and application of loops

Explanation -

This question involves the simple use of Pythagoras Theorem, if the x co-ordinate or the y co-ordinate of the food and snake are same the answer can be calculated using simple arithmetic subtraction. If food lies on any diagonal element started from the snake then we can simply use Pythagoras theorem.

The main problem arises when the location of food is not on the diagonal with respect to snake, then we have to first calculate the position of the snake with respect to food then we have to move in that that direction diagonally. Then once we reach the position which is on the diagonal that is closest to the food then we can simply linearly transverse and reach the food.