Our social:

Tcs codevita season 5 round 1 longest possible route program answer (solution )

Given an MxN matrix, with a few hurdles arbitrarily placed, calculate the cost of longest possible route from point A to point B within the matrix. 



Input Format: 

First line contains 2 numbers delimited by whitespace where, first number M is number of rows and second number N is number of columns
Second line contains number of hurdles H followed by H lines, each line will contain one hurdle point in the matrix.
Next line will contain point A, starting point in the matrix.
Next line will contain point B, stop point in the matrix.

Output Format: 

Output should display the length of the longest route from point A to point B in the matrix. 

Constraints:

The cost from one position to another will be 1 unit.
A location once visited in a particular path cannot be visited again.
A route will only consider adjacent hops. The route cannot consist of diagonal hops.
The position with a hurdle cannot be visited.
The values MxN signifies that the matrix consists of rows ranging from 0 to M-1 and columns ranging from 0 to N-1.
If the destination is not reachable or source/ destination overlap with hurdles, print cost as -1.

If you have solved this question help other to solve comment your answers and doubts ..!!
We will post answer as soon as possible,...!!