🎁 Exclusive Offer! Join our
Telegram Channel
to get **special discounts** and updates! 🚀
Question 21 - 100% Working Solution | Buy Now
Description
7 Live
The city of Hackerland can be represented using a grid with n rows and m columns containing an empty cell represented by a '*' and a blocked cell represented by a #. Traveling is allowed only through empty cells. The people of Hackerland are required to travel from a starting cell defined by the character 'S' to an ending cell represented by a character 'E'.
The people can jump a length of any integer k in all four directions from a given cell i.e. up, down, left, and right. However, if the jump length kis greater than 1, the next jump must be made in the same direction, For example, a hacker is allowed to jump 3 units towards the right, followed by 1 unit towards the right, and then 3 units towards the left. They however cannot jump 3 units towards the right followed by 1 unit towards the left as direction change is not allowed if the previous jump was of length greater than 1. Note that the last jump in any jump sequence is always of length 1.
The jump can be made over a blocked cell as well as long as both starting and ending cells are empty.
Given the map of Hackerland as a 2g matrix grid, that contains exactly one 'S' and 'E' each, find the minimum number of jumps required to travel from Sto E. Report -1 if it is not possible to reach E from S.
Example
Suppose n = 5, m = 6 and grid = ["S **** #". ******** ******* ******** " ***** E")